sed is a command-line stream editor for filtering and transforming text.

learn more… | top users | synonyms

5
votes
2answers
2k views

Delete till first occurrence of colon using sed

My sed command is, sed '/(.*:)/d' <<< 'abcd:bcde:cdeaf' It must return, bcde:cdeaf (i.e.) all characters before the first colon in the line and the colon itself must be removed. But ...
1
vote
1answer
83 views

Ignore full lines with sed

I've searched high and low across the internet, but I can't seem to find an answer that satisfies this question - I need to use sed to display all lines in a file, excluding a group of them. I'm not ...
0
votes
1answer
389 views

How do I find block of text, from a text file, containing a specific string [duplicate]

I've been looking to extract a block of text, from a text file, containing a string with no success. Any help would be really appreciated. For example: I have a file named xyz with below contents: ...
1
vote
2answers
76 views

sed - how to print text block from the second pattern?

I have an html page that contains two tables. Both tables begin with the same tag "<table role="grid">" and I want to display the second table code. For now, I know only display the first with:...
0
votes
1answer
140 views

sed html parsing

I have to parse HTML to change text between two brackets that are not HTML code back to &lt; or &gt;. Here an example of my HTML code that I have to replace: <content:encoded><![...
1
vote
2answers
98 views

how to swap text inside files [duplicate]

Inside my file I need to swap places of all instances of : grep 'search string' and sed '/string of text/,/string of text/{//!d}' In VI I have tried a regex with no luck - it says something ...
3
votes
4answers
881 views

How do I remove first character in specific column using sed

I have file with the next structure: 999963803|081439403|FFF|33 999964211|081823904|FFF|33 999970948|081765738|FFF|33 999971835|081736346|FFF|33 999972780|082127527|FFF|33 I need remove the first ...
0
votes
1answer
18 views

Is there a way to get all the NEWS.gz which is/was this year in /usr/share/doc/ of $PACKAGENAME

If people go into /usr/share/doc/$PACKAGENAME (you can use any valid package name which you have installed on your system) you will see that the directory has various files in it, at the very least ...
0
votes
3answers
70 views

Null value than rename file

I have a shell to a task but I should handle the null value in this. So in the task i cut the part of a word and i delete or rename the file, but need another if element for null. For example: I ...
0
votes
1answer
51 views

How can I replace a filename with .ear in a file-list using sed?

I have a file whose contents look like: /appl/as/var/spool/ears/mps/ear1.ear ... I want to replace the name of only ear1.ear with ear2.ear and I am using the below sed command, but with no luck: ...
0
votes
4answers
189 views

sed Remove lines ending in [0-9]%

I'm writing a script that logs stdout-stderr. The log contains multiple instances of: (Reading database ... (Reading database ... 5% (Reading database ... 10% (Reading database ... 15% (Reading ...
2
votes
2answers
422 views

How to delete comments for java project with sed?

I have a Java project, in which I have JavaDoc comments /** ... */ other multi-line-comments /* ... */ line comments // ... and my own "explanatory comments" //* ... When I release my code,...
-1
votes
4answers
97 views

How to break a string into smaller substrings with a condition on their lengths?

I have a file that contains some genetic sequences like this one: ...
3
votes
3answers
121 views

How to remove duplicate lines that begin with a pattern and the next line after that?

I want to remove duplicate lines that begin with > and the next line after that. For example: >1 ACCGGTTTCCTTGAAATT >2 AACCTTCCGGTTAATT >3 AACCTTCCGGTTAATT >1 ACCGGTTTCCTTGAAATT ...
2
votes
1answer
167 views

Named serial increment SED oneliner

I need to increment named serial and I want to do it with sed. I've done it like this: echo 2015092315 | gsed s/20[0-9][0-9][0-9][0-9]*/`date +%Y%m%d%H`/g But then I realized that updates to zone ...
0
votes
2answers
59 views

SED Multi-line substitute and hold space

I had some time to try and learn more SED this week and have been experiment with the following sample code: </td> <td> <h4 class="text-danger" style="display: inline;"...
1
vote
2answers
473 views

Extract data between two matched patterns in a binary file

I am trying to extract a jpeg image from a binary text file. I want to extract all data between 0xFF 0xD8 (start of image) and 0xFF 0xD9 (end of image) inclusive. Earlier, I have successfully run the ...
4
votes
2answers
276 views

split a large file to new file with unique file names

I need to split a file into unique file names. I can do it with sed command eg, sed -n '/scaffold135_/w 135-scaf.txt' input file.txt but it's time consuming so I need a smart way to do it faster. ...
3
votes
3answers
184 views

Sed to edit header with the contents of another file

I am trying to replace an existing header in a file based on the contents of another file. File1 - names.in: name1 name2 name3 name4 name5 File2- Datafile.tsv: chr begin end genes genes genes ...
1
vote
1answer
41 views

Array from piped commands fails

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank. I'm trying to write a script that will auto-mount our ...
0
votes
3answers
39 views

Is it possible to replace </sys:String> with sed command?

I have been trying to replace with using this command sed 's/</sys:String>/ /' but it doesnt work.
1
vote
1answer
97 views

Why is vi (but not cat) showing ^[[31m[^[[m^[[31m" after I use sed and output to a file I then edit? [closed]

When I use cat Variables/user-extensions.js | sed -e 's/css/XXX/' on an input file of the form storedVars["css_body"] = "css=body"; storedVars["css_main"] = "css=main"; I see output such as ...
3
votes
7answers
158 views

How to replace line with file contents and around the content with some text?

I would like to combine VPN certificates into a single file. This is a template file: # some unrelated stuff ca ca.crt # other unrelated stuff And I want to replace line ca ca.crt with the ...
1
vote
1answer
535 views

sed - how to use \b word boundary correctly?

I want to replace quotes that are at the start of a word. For example: $ echo "a 'line' a single ' after a 'keyword' with a few space's for a program"\ | sed "s/\b'/X/g" a 'lineX a single ' after a ...
6
votes
4answers
511 views

Delete column that includes a specific text

I was looking for an option to delete a column with a specific text like "ddd" aaa bbb ccc ddd eee fff 1 2 3 4 5 6 2 3 4 5 6 0 So that the output looks likes this: aaa bbb ccc ...
1
vote
1answer
193 views

Sed replace portions of lines not beginning with http://

I'm getting stuck with sed.. I'm trying to prefix links in an html file with a / when they don't start with http.. I'm aware this is possibly not the best way to go about this but I'm just after a ...
0
votes
3answers
61 views

How to correctly use quotes in sed? [duplicate]

For example I want to change "'this text'" "that text" 'other_text' into 'this text' "that text" 'other_text' I tried sed -e 's/^"\'/"/g' but my quoting must be off. Ubuntu.
2
votes
1answer
253 views

replace nth column of a csv file by the help of lookup table

I have a csv file (a.csv) as below (with thousands of lines): NMS_NE,,,,,,,,,,,,,,,,,,,,,,, D,NE Name,IP Address,Site Name,Product UPEI,Product Name,Product Model,NE Status,Serial Number,SW Major ...
-1
votes
1answer
37 views

Get the respective tablenames if it matches particular pattern

I need to list the table names if it finds particular pattern from the below file. CREATE TABLE IMS.ACTIVITY ( "ID" INTEGER NOT NULL , OWNING_TYPE FOR COLUMN OWNIN00001 VARCHAR(20) ...
1
vote
1answer
46 views

append few strings at the start and bottom of string coming from file read

I am working on a shell script which is getting data from another program and I am using that variable value to read the content from file and append few things inside those data at start and bottom: ...
-1
votes
1answer
1k views

How to fix 'command a expects \ followed by text' in my sed? [closed]

I have the following snippet in a sed statement: /pause$/ { N; /pause/d } but I'm getting: $ . sed_shorter_version_one_test_case_html_to_ruby.sh SAD/fullform_SAD sed: 19: " /pause$/ { N; /...
0
votes
1answer
165 views

How to use content address in sed on osx without error “expected context address”

I'm getting this error sed: 2: " /^[[:space:]]*pause$/, ...": expected context address with this line: /^[[:space:]]*pause$/,+1d which works on my debian Ubuntu system. The full file is ...
0
votes
3answers
120 views

How to remove <td> or </td> with sed?

I am successfully using: s/^[[:space:]]*<[/]*tr.*>// to change any lines starting with <tr> or </tr>, removing those tags. However when I try using s/^[[:space:]]*<[/]*td.*&...
3
votes
4answers
355 views

How to remove <?xml at *start of line* with sed?

I have a file whose first line starts with <?xml I can remove it with sed using /<\?xml/d but if I try and ensure start of line - /^<\?xml/d it doesn't match. However other lines such ...
4
votes
3answers
570 views

sed, convert single backslash to double backslash

I have a json string, which has a potpourri of doubly escaped/singly escaped newline chars. Json parser doesn't allow its string value to have single backslash escapes. I need to uniformly make all ...
0
votes
1answer
555 views

Getting RE error: repetition-operator operand invalid on osx sed

I'm copy a sed script form Ubuntu debian to osx but getting RE error: repetition-operator operand invalid What is wrong? $ . sed_shorter_version_user_extensions_to_ruby.sh sed: 22: " ### DELETE ...
0
votes
4answers
103 views

Sed, remove all comments in a file [duplicate]

I have a sed command that removes comments in a file as, sed -i /^#/d /path/to/file This works but not when the comments are indented/have a preceding space. like #this is a good comment ...
6
votes
2answers
3k views

Join multiple sed commands in one script for processing CSV file

Having a CSV file like this: HEADER "first, column"|"second "some random quotes" column"|"third ol' column" FOOTER and looking for result like: HEADER first, column|second "some random quotes" ...
2
votes
1answer
160 views

dpkg: error: duplicate file trigger interest for filename `/usr/lib/gio/modules' and package `libglib2.0-0'

[Reposted from askubuntu.com] I can't install any software. I think this dates from an unexpected power loss a few days ago. When I try sudo apt-get install gparted I see Reading package lists... ...
0
votes
1answer
61 views

Replace a string with “string|string”

I have a pretty weird problem. I did some calculations for bioinformatics, but my downstream apps won't accept my header information in its current format. In order to circumvent this I modified my ...
0
votes
1answer
39 views

How to SED with open boundaries? [duplicate]

I was thinking too complicated the slicing in the How to express variables efficiently for SED? I want to include (a,b), not [a,b] like this don_crissti's command: sed '/begin{document}/,/end{...
0
votes
1answer
49 views

How to express variables efficiently for SED?

There are many ways to express arithmetic things: new and old ways. However, I would like to write this line efficiently and well sed -n '$START,$ENDp;$ENDq' < data.tex which output sed: 1: "$...
1
vote
3answers
148 views

Replace arbitrary characters in the middle of an IP address string with sed

I need to find and replace either one or two numerical characters in strings in a file. The strings are IP addresses of the form: 10.xx.y.z Where xx can be one or two characters. I want to ...
2
votes
4answers
131 views

How to add hyphens at the first empty line of a text file?

I'm trying to add three hyphens to the first empty line of a given text file, and am trying to use sed for this. My initial file (a MultiMarkdown file) looks something like this: title: "Ch. 1: ...
0
votes
2answers
38 views

How to get the sed command to only search for full words?

I'm fairly new to Linux and recently started experimenting with the command line. I decided to make a file and called it 'hi.txt'. The contents of the document was: This is hi.txt. hi hi hi I ...
1
vote
2answers
38 views

Reading a variable-sized line and splitting its content into separate lines with text

I have a file with the header (first line) with a variable length; and it comes as: "One"|"Two"|"Three" or "One"|"Two"|"Three"|...|"One Hundred" and want to get do a loop that transforms it ...
4
votes
4answers
641 views

Replace “/” with “\/”

I have a string /tmp/testing which I want to replace with \/tmp\/testing sed works fine as follows: echo testdir=/tmp/testing | sed 's/\//\\\//g' testdir=\/tmp\/testing However if I try and put ...
1
vote
3answers
61 views

how to remove first occurrence of 0 in mm/dd a date using sed?

I want to remove first occurrence of 0 in mm/dd, e.g. I want to make 09/09/15 look like 9/9/15. I have tried using echo 09/10/15 | sed 's/^.//' but it gives output like 9/09/15. How can I do this?
0
votes
1answer
97 views

Sed dynamic substitute, the unix way?

Got a bunch of files with domain qualified names in them, looking to replace them by their ip. Can I do that with one line of shell ( bash ) ? Typical input file ( nagiosconf ) : define host { ...
4
votes
4answers
1k views

sed - Print lines matched by a pattern range if one line matches a condition [duplicate]

I have a multi line log entry format that I need to process. The log looks something like this: --START-- Device=B Data=asdfasdf Lorem=Ipsum --END-- --START-- Device=A Data=asdfasdf Lorem=Ipsum --...