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

learn more… | top users | synonyms

4
votes
3answers
459 views

Want to search for two consecutive lines with at least n characters

I would like to use sed to search for the first part of a text file with consecutive lines with at least n non-space characters. I would like to print from the first of those lines to the end of the ...
8
votes
7answers
415 views

Swapping an unlimited number of columns

I have a file with columns. See below for an example: a b c ... z 1 2 3 ... 26 I'd like to swap all columns where the 1st becomes the last, the second becomes the one before last...etc.. z y x ...
2
votes
1answer
439 views

Using sed, how can I replace a line containing a pattern with contents from another file?

input_file.txt: one fffds two xxxx three ffff four ffde data_file.txt: six seven I want to replace the line containing two xxxx in input_file.txt with the content of data_file.txt. The output ...
4
votes
1answer
697 views

How is this sed command working?

I want to understand, how following sed command is working: sed -nre "/jar$/ { x; d; }; /class$/ { x; p; } Actually it is part of another command to find a particular class file from the given list ...
5
votes
3answers
3k views

How to embed a shell command into a sed expression?

I have a text file with the following format: keyword value keyword value ... Where keyword is a single word and value is everything else until the end of line. I want to read the file from a shell ...
1
vote
2answers
629 views

Parsing the output of date with sed

I am trying to replace the whitespaces in the output of date with '_' with no success. $date Fri Sep 14 14:10:04 EDT 2012 $ date | sed 's/ /_/' Fri_Sep 14 14:10:24 EDT 2012 As you can see, the ...
3
votes
4answers
5k views

How to get all lines between first and last occurrences of patterns?

How can I trim a file (well input stream) so that I only get the lines ranging from the first occurrence of pattern foo to the last occurrence of pattern bar? For instance consider the following ...
4
votes
3answers
1k views

with sed, how can I replace word within a matching line?

I am trying to write a sed expression to detect lines similer to this: s0:12345:respawn:/sbin/agetty -8 -s 115200 ttyS0 linux and replace the "ttys0" with "something_else" I do not want to detect ...
6
votes
4answers
4k views

Concatenate lines by first column (AWK or SED)

How can I use AWK in the following situation? I want to concatenate lines that start with the same column. Only the first column is kept after the join (in this case aaa, www, hhh). The file may be ...
0
votes
5answers
6k views

compare two files get identical list

file1.txt (50 lines) TERYUFV00000010753 TERYUFV00000009526 file2.txt (500 lines) TERYUFV00000009526 refids_739_known_8/10_target TERYUFV00000018907 refids_12023_known_21/22_target ...
4
votes
3answers
785 views

sed convert 4 spaces to 2

How does one convert 4 spaces into 2 spaces with sed? Is it possible? I found this but it converts tab to spaces: sed -r ':f; s|^(\t*)\s{4}|\1\t|g; t f' file
2
votes
3answers
118 views

Need to parse a double entry table with two pairs

I have this two-entry table resulting from a program output: Variable1 : Value1 Variable2 : Value2 Variable3 : Value3 Variable4 : Value4 Variable5 : Value5 Variable6 : Value6 ...
2
votes
1answer
1k views

update PATH variable in .bashrc using sed

I've been trying to update my PATH variable permanently by putting it in my .bashrc file. However, I don't want to just append it to the file, but rather replace the current PATH=........ with the ...
0
votes
2answers
211 views

Getting data from matching list

list.txt GETID_17049_knownids_1/2_Confidence_0.625_Length_2532 GETID_9248_knownids_6/10_Confidence_0.439_Length_2474 GETID_11084_knownids_3/3_Confidence_0.600_Length_1451 ...
1
vote
5answers
6k views

(Mac Terminal) sed to parse JSON … what am I doing wrong?

In Mac Terminal, I'm trying to parse the "name" out of this JSON response: {"created_at":"2012-08-27T20:04:27Z","deleted_at":null,"id":21462840,"item_type":"video","name":"CastingBy-v12 ...
4
votes
2answers
153 views

Column mismatch and substituting

input.txt (tab-delimted) TTTTOTTT00000000008 RTTTT899 5.00E-28 TTTTOTTT00000000046 RTTTWRR 3.00E-31 TTTTOTTT00000000051 2.00E-11 TTTTOTTT00000000051 7.00E-12 TTTTOTTT00000000054 ...
1
vote
1answer
115 views

Match slash in bbe

How can I match a forward slash in bbe? If I have this text file called test.txt: foo / bar I can match it in sed like so: sed -e 's/foo \/ bar/it worked!/' test.txt However when doing the same ...
9
votes
2answers
2k views

Using sed to color the output from a command on solaris

I have a ksh script that must work on both linux and solaris. I'm trying to color the output of specific commands. It works on linux (specifically RHEL6), but not on solaris (SunOS 5.10). Command ...
2
votes
1answer
5k views

Delete specific line number(s) from a text file using sed?

I want to delete one or more specific line numbers from a file. How would I do this using sed?
4
votes
1answer
4k views

Delete last character in a word but only if the character is there - in bash

How to remove last character only if it's there? input: OpenOffice.org/m openOffice.org/ozm Pers. Pfg. phil. Prof. resp. Roonstr./m roonstr./ozm desired output: OpenOffice.org openOffice.org ...
5
votes
3answers
498 views

Gedit or an other non-commandline editor with the ability to spell-check two languages at the same time

I'm searching for an editor with the ability to spell-check two languages at the same time (German and English). Gedit can't do it out of the box. But I want to use Gedit. It should be possible by ...
2
votes
2answers
375 views

How to Wrap a file with Tags in Bash

I have an xml file named test.xml, without a root tag like this: <cat></cat> <name></name> <id></id> <cat></cat> <name></name> ...
1
vote
4answers
2k views

Appending a string containing escape character with sed

Currently I use: sed -i -e "5a\\ ${text}" $filename to append something to a certain line, where the variable text contains a string such as "\epsilon". When using echo -E $text the string is ...
2
votes
2answers
335 views

Get row data for non-matching column values

I want to read the file (1600 rows) and get rows only the columns have different values (sno1, sno2, sno3 & sno4-should be not be equal value) and it should be above 50%.The example of output ...
3
votes
2answers
356 views

Print row contain maximum and minimum value

I need to read the file (contains 16K rows)and print the entire row if any of columns and all columns contains max value (100) and all columns contain min value (0).The ouput example is given ...
2
votes
3answers
12k views

Sed : Replace pattern on every second occurence?

Is there a way to tell sed to replace the pattern on every second occurrence? Or at least on every second line? (Sure it's possible with a script, but I was asking myself if sed can do it to). ...
1
vote
2answers
276 views

Matching values within columns

I have tab-delimited text file containing about more than 1500 rows. input.txt id sno1 EN1 Nucus_2158_mri_1/2_Co_1.0_Le_3104 EN2 Nucus_2158_mri_4/2_Co_1.0_Le_3104 EN3 ...
4
votes
4answers
991 views

Replace whole line in a file from command-line

I have a text file which has some contents similar to this: # General information about the project. project = u'Py6S' copyright = u'2012, Robin Wilson' # The version info for the project you're ...
4
votes
2answers
4k views

Working with columns - awk and sed

I am trying to parse a text file that is generated by an expec script that pulls down some information from a switch. Here is a sample output: 192 0000.0000.0000 1/g23 Dynamic ...
3
votes
2answers
98 views

What is the usage of pattern before substitute command in sed

There is an example in this link about sed: To delete the first number on all lines that start with a "#" use: sed '/^#/ s/[0-9][0-9]*//' What is the benefit of first pattern(/^#/)? It could be ...
1
vote
2answers
159 views

Can sed be used to generate a load file for my date lookup fact table?

I have an SQL fact table which is used for looking up a date and returning another date. The table schema is as follows: TABLE date_lookup ( pk_date DATE, plus1_months DATE, plus2_months DATE, ...
6
votes
1answer
10k views

Only return the matched string in sed [duplicate]

Possible Duplicate: Extracting a regex matched with 'sed' without printing the surrounding characters How do I make this only print test: echo "atestb" | sed -n 's/\(test\)/\1/p'
7
votes
3answers
2k views

How can I instruct BSD sed to interpret escape sequences like \n and \t?

I have a sed replacement command that I would like to be compatible with BSD sed as well as GNU sed. Extended regular expressions are not an issue as I do not need them in this case. My primary ...
4
votes
2answers
7k views

Compare two file columns

I have long text files with space-delimited fields: cat file1.txt Id leng sal mon 25671 34343 56565 5565 44888 56565 45554 6868 23343 23423 26226 6224 77765 88688 87464 6848 66776 23343 63463 ...
3
votes
2answers
492 views

Parsing a text-file table and aggregating information

I have long text file with the following columns, space-delimited: Id Pos Ref Var Cn SF:R1 SR He Ho NC cm|371443199 22 G A R Pass:8 0 1 0 0 ...
2
votes
1answer
527 views

Duplicate selected words with sed and replace it

I have to modify a document containing xml data; one modification I couldn't set up with sed. I have to modify the following expressions from: <Bild ...
2
votes
2answers
639 views

remove only specific text occurrences from string using sed

I have a text file that contains many rows of this sort of thing: /*[17:51:27][1 ms]*/ UPDATE `country` SET `region_id` = '4' WHERE `country_id` = '36'; Is there a way that I can use sed to remove ...
4
votes
2answers
2k views

delete first line of file only if blank using sed

I have a solution for this in awk: awk '{if (NR==1 && NF==0) next};1' somefile but was unable to find one that worked in sed. E.g., sed -i.bak '/^$/{1,1d;}' somefile ended up deleting ...
8
votes
6answers
240 views

Grab certain contents of a file

So I know tools exist for this problem because I've heard about them, but I don't know what they are. I want to do something like filter out all data but the usernames in /etc/passwd. For example, I ...
10
votes
3answers
4k views

How to sort the string which combined with string + numeric using bash script?

This is the data what I want to sort. But sort treats the numeric to string, the data it no sorted as I expected. /home/files/profile1 /home/files/profile10 /home/files/profile11 ...
3
votes
6answers
2k views

Text file look-up by column

I have a file in this format: [#] OWNER_NAME NAME SIZE [6] Robottinosino Software 200 [42] Robottinosino Ideas worth zero 188 [12] ...
3
votes
2answers
474 views

Change string occurrences in file while respecting DOS new line sequences

I use Visual Studio for my C# development while using Cygwin for some of the tasks that require scripting. Recently I wanted to change all occurrences of string AAA to BBB in my project's files. I ...
2
votes
4answers
932 views

shorten long lines in a log file

I keep a logfile of a program's output. The trouble is sometimes errors occur dumping very long lines of 7bit ascii data(encoded binary) I don't care to keep. These lines can be 200KB+ long before ...
3
votes
3answers
2k views

Using sed to edit lines in a file with a variable

I need to edit lines in a file using sed. Now the problem is I am replacing a particular pattern with a combination of text and number. This number is a variable which keeps on incrementing for every ...
1
vote
2answers
274 views

How to split vCards lines

Related to How to join vCards lines, vCard does a weird kind of line splitting: If a line contains more than 75 characters, insert a "CR, LF, space" sequence. Thus the following line: ...
3
votes
4answers
887 views

Strip spaces after single capital letters with sed

I am writing a bash script to automatically generate some other files, and I have to format some strings a certain way. Specifically, the last problem I'm having is formatting a string that has ...
-5
votes
1answer
326 views

sed and awk challenge [closed]

Here is a great challenge for someone to attack! Is there a way to achieve the following using sed and/or awk. Please see myfile.txt below: $cat myfile.txt: entry "entry-header" entry-top name ...
2
votes
3answers
2k views

Grepping several lines from Nmap output

I apologize in advance as this is a simple question. So I'm attempting to scan a Class C to identify all mail servers by IP. The vast majority of IPs aren't mail servers. I'm trying to filter out the ...
2
votes
1answer
269 views

Replace “<?php print t('Blabla'); ?>” to be “Blabla”

Lets say in file.php, there is lots of php print text: <?php print t('Blabla'); ?>, <?php print t('Text Here'); ?>, etc. What I need is to remove <?php print t(' and '); ?> of the ...
8
votes
2answers
12k views

How to replace a string with a string containing slash with sed?

i am looking for a way to replace a string in a file with a string that contains a slash by using sed. connect="192.168.100.61/foo" srcText="foo.bar=XPLACEHOLDERX" echo $srcText | sed ...