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

learn more… | top users | synonyms

1
vote
1answer
1k views

Deleting commented lines in a text file using sed

I am a sed novice. I would like to use sed to delete commented lines in a text file. In my series of text files, commented lines begin with either the # symbol or the @ symbol (i.e., they are ...
0
votes
3answers
133 views

Removing second colon

Trying to create a simple script that lists mass mailing by the queue number that appears in /var/log/maillog. I'm starting off with this: [root@ditirdlns01 ~]# lsMails(){ grep -i ...
1
vote
5answers
489 views

Need some sed magic: Moving marked lines to the beginning of a file

I find myself in dire need of some sed magic (I really need to sit myself down and learn this). I have a file with lots of lines. After reviewing it, I've marked some lines by adding a star (*) to ...
1
vote
2answers
2k views

How to use sed with round brackets?

I have a bunch of .php files that I wanted to replace all occurrences of a string. find: jQuery(function replace: head.ready(function I thought I was doing it right by using: find . -name '*.php' ...
3
votes
3answers
5k views

extract part of string using sed

ls lib/oracle-11.2.0.3.0.txt | sed 's/lib.\([oracle.*]\)\.txt/\1/' It is giving the whole string instead of just oracle part until .txt What am I doing wrong? I can do it using awk as follows, but, ...
2
votes
2answers
425 views

Add a suffix string to end of each line? [duplicate]

I have two files: file01: line1 line2 line3 file02: A B C And I want to get line1 A line2 B line3 C I could possibly write a Perl script but it is better if I don't need to. I have tried ...
0
votes
4answers
4k views

Extract substring using regular expression on a Unix file

I have file with below contents . /ABC/RTE/AD_900_VOP_123/OPP /ABC/RTE/TRE/AD_900_VOP_145/BBB /ABC/RTE/AN_900_VFP_124/FBF /ABC/RTE/HD_900_FOP_153/WEW /ABD/RDV/AD_900_VOP_123/OPP ...
3
votes
1answer
123 views

How to follow and seek in a file being piped through a filter, in less

I basically wish to seek, search and follow a growing log file after passing it through a sed filter. I figured I need to follow a file with tail -f pipe it to sed and then pipe that to less. For ...
4
votes
4answers
606 views

What does <<< mean? [duplicate]

What does <<< mean? Here is an example: $ sed 's/a/b/g' <<< "aaa" bbb Is it something general that works with more Linux commands? It looks like it's feeding the sed program with ...
2
votes
2answers
151 views

linux & solaris - separate netmask IP's from ordinary IP's

I have file with IP address and netmask IP's my target is to cut the netmask IP's from the file_with_IPs.txt and paste them to another file as file_with_only_netmask_ips.txt remark - netmask IP can ...
-3
votes
4answers
589 views

perl one liner + how to replace any last IP address octets

How to replace any last IP address octets (four octet ) to 0 remark: Implementation should be by Perl one linear on linux machines for example 192.9.200.124 will replaced to 192.9.200.0 ...
-1
votes
1answer
211 views

SED command and filenames with space

I was hacked, for my php files was infected. Example: http://www.nwww.ma.mk/oscommerce/configweb/apexfash-wp-blog.txt Bad Code: <?php ...
2
votes
4answers
2k views

Using sed, how to format one word per line, removing white space

I'm trying to replaces patterns and cleanup a file containing multiple words to get one word per line. The result is achieved using this command line: sed -e '/^[[:space:]]*$/ d' \ # ...
5
votes
1answer
2k views

Removing leading zeros from DATE

I made an alias of the date command to display date in the following format: 2013.06.14.12.10.02 using this command: alias date = date +"%Y.%m.%d.%H.%M.%S" Everything works great, except I ...
4
votes
2answers
382 views

Use sed or awk to join lines in a certain pattern?

Not sure on how to turn this input: A B C apartner bpartner cpartner into this output: A apartner B bpartner c cpartner I have this pattern in a 80 line file that needs to be 40 line. Also, how ...
-2
votes
3answers
396 views

run file from different directory [closed]

I have a directory mainfolder with a subdirectory execution which contains a configure script. I can switch to the execution directory and run ./configure and it works fine. Now I'm trying to figure ...
3
votes
6answers
8k views

Using sed to find and replace complex string (preferrably with regex)

I have a file with the following contents: <username><![CDATA[name]]></username> <password><![CDATA[password]]></password> ...
4
votes
3answers
1k views

print lines between start and end using sed

I need to print the lines between two delimiters. For example, given the input fluff1 fluff2 BEGIN good3 good4 END fluff5 fluff6 BEGIN good7 good8 END more fluff I want the output to be good3 ...
2
votes
3answers
135 views

Delete lines containing repeated text

I have a file containing two paths on each line. I want to remove the lines containing the same path twice. I work on Linux and Solaris. I would like a one-liner in sed or awk or perl. Example input ...
0
votes
4answers
67 views

How to make 1:52 to 01:52 with eg.: sed?

INPUT: a|2013.06.13. 13:22|xx b|2013.06.13. 1:52 |xx c|2013.06.13. 2:26 |xx OUTPUT: a|2013.06.13. 13:22|xx b|2013.06.13. 01:52 |xx c|2013.06.13. 02:26 |xx How can I make the 1:52 to 01:52 in ...
2
votes
3answers
913 views

I want to find duplicates in a file and add a character to the end of the line on the 1st match

I am trying to find duplicates in a file and once a match is found mark the 1st match with a character or word on the end of the line. eg my file (test.html) contains the following entries host= ...
2
votes
1answer
140 views

Replace every odd or even occurance of a pattern in a file

I want to replace either every odd or even occurrence of a pattern. Look at the following example: $ echo aaaaa | sed -e 's/a/b/' -e 's/a/c/' -e 's/a/b/' -e 's/a/c/' -e 's/a/b/' bcbcb Is there some ...
2
votes
2answers
2k views

Replacing text between two HTML Comments

I am new to the world of sed/awk and regex in general and have been studying their usage, but have been floundering trying to meet my need: I have an htm page that has a single line notice that needs ...
0
votes
3answers
184 views

Inserting the results of a for loop into an html file - BASH

I have a script that takes the results of a command and puts them into a html code. Here's what I have so far... #!/bin/bash list_dir=`ls -t downloads/` for i in $list_dir do #---- # echo ...
2
votes
2answers
351 views

sed command to leave two decimals and remove the rest after comma

I have a numeric value, for example 19.3478 or 22.456 or 10. I would like to remove extra decimals if there are more than two decimals, so that there is never more than two decimals after the comma. ...
2
votes
3answers
2k views

Easy way to parse syslog date format

I'd like to write a script that analyses the last week's syslog. But my syslog logs in a stupid date format, e.g. "May 22". If it logged as 2013-05-22, this task would be trivial. Is there a way ...
2
votes
1answer
112 views

SED Showing CRLF While Vim Not Showing

Why sed l\;q shows a CRLF while opening the file in Vim with :set list doesn't show any CRLF
4
votes
3answers
2k views

How to sed a range of lines?

I have this: sed -i '/^$/d' temp_spec.rb which is stripping blank lines and works well. How can I make it only do this for lines 5-999 (or ideally 5 to end-of-file). I tried: sed -n5,999 -i ...
3
votes
3answers
96 views

How to select 30 files and do a bunch of sed commands on them

I want new copies of the files, so I want to do something like: dir *.rb foreach file make a copy of the file, e.g. 'blob.rb' to 'blob_processed.rb' do the 50 sed commands to process the ...
2
votes
7answers
4k views

Can sed remove 'double' newline characters?

I have a document with a lot of empty lines. How can I remove them when there are 2 or more together. I tried sed "s/\n\n//" file but it didn't work. No error.
2
votes
3answers
2k views

sed - how to replace a single quote?

This works fine: sed -i 's# @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb against a source of @driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click ...
5
votes
4answers
457 views

sed how to substitute when string has “http://” in it?

I have a file xx that has the following contents: @base_url = "http://dmstaffing-stage.herokuapp.com/" I want to use sed to eliminate this line (replace with nothing). I have used this sed ...
3
votes
2answers
823 views

How to only substitute lines that match several patterns in sed?

$ echo -e 'CH12\nCH23au' | sed '/^CH/s=^=<b>=' <b>CH12 <b>CH23au I know I can match lines starting with CH by ^CH but how can I match multiple patterns? Example: Input: CH12 ...
2
votes
0answers
1k views

sed couldn't flush stdout no space left on device?

What could be the reason for this error : sed couldn't flush stdout no space left on device This is come of the stuff that i am doing at last in my code sed -n '/.*needs to be executed ...
3
votes
3answers
1k views

How to share a GNU sed script between Linux and Mac OS X

I have a GNU sed script I use on Linux; it is installed at /bin/sed and it seems it contains GNUisms. I have collaborators using Mac OS X. They have installed (non-GNU) sed, located at /usr/bin/sed, ...
3
votes
3answers
161 views

sed + how to remove character/s that start or ended on each number

How do I remove the . character(s) that start in the beginning of each number or end on each number? Remark – perl one liner also good alternative for sed. Example input: .23.12.44.5. .233.3.3.3 ...
3
votes
3answers
168 views

checking data in columns when a data or some may be missing or present?

I am not sure if this possible. say i have columns like : Team Colour Game Rainfall PlayerName XYZ Blue Cricket Yes Kapil suppose i need to search ...
2
votes
2answers
282 views

remove only the first blank line sed

there are similar questions here but none matches my problem exactly. How do I remove only the first blank line from a file using sed? Let's say I have a b c And I want a b c As output.
5
votes
4answers
2k views

Why is sed giving me an error about an unterminated `s'?

I have a set of sed replacements in a bash script and am getting an error about an unterminated `s' command. Here's what the sed line looks like: sed -n -e "s/TMPFOO1/$FOO1/" -e "s/TMPFOO2/$FOO2/" ...
3
votes
3answers
87 views

how to form a sed expression containing escaped characters

Given a sed expression (and GNU sed 4.2.2 on ArchLinux) /match/i\tline1\n\tline2 which should insert two tab-indented lines above the match, I find that the escaping of the first character (in the ...
1
vote
2answers
179 views

Split using sed

I have to split [X] ||| you owns the [X,1] ||| you own the [X,1] ||| 1 0.02020 0.07847 0.36788 3 -0.00000 -0.00000 at the pipes and output those line whose 2nd and 3rd argument are different.
5
votes
3answers
4k views

Use sed to find whole word and replace

I have the following block of text in a file: test3.legacy test4.legacy test3 test3.kami I only want to search for test3 as a whole and replace it with nothing. Unfortunately, all my attempts have ...
0
votes
1answer
2k views

sed, getting an error: sed -e expression #1, char 28: unterminated `s' command

When I do: sed 's/@driver.quit/#@driver.quit' set_QA_district_name_spec.rb I get the error shown in the title. How can I get around this error, what is wrong?
4
votes
2answers
935 views

sed pattern space and hold space

i was just going thorugh this and i was unable to understand. sed -n '1h; 1!H; ${ g; s/foo\nbar/bla\nblub/ p }' file. where cat file is : foo foo bar why there is 1!H because to me 1h ...
1
vote
2answers
283 views

Delete lines until a header with sed [closed]

I am incorporating SED into a Windows batch file. I've got it working for deleting the first seven lines of a text file: SED "1,7d" However, I'd like to make it a smarter statement. Essentially, ...
4
votes
3answers
5k views

How can I use SED or AWK to replace placeholders in a template file with variable content that contains special characters?

CentOS 6.3 I'm trying to get a small script to send an email containing a copy of email headers in the body (for the purpose of internal reporting). The template file contains the following: ...
4
votes
3answers
2k views

Remove string from a particular field using awk/sed

I have a file (>80,000 lines) that looks likes this: chr1 GTF2GFF chromosome 1 249213345 . . . ID=chr1;Name=chr1 chr1 GTF2GFF gene 11874 14408 . + . ...
1
vote
3answers
91 views

Does sed write to the file or give a sample output

when using sed with a file like this sed 's/a/o' fruits it gives the necessary output to the terminal but it does not change the contents in the file. How do I permanently change the file with the ...
0
votes
1answer
786 views

comparing lines with awk vs while read line

I have two files one with 17k lines and another one with 4k lines. I wanted to compare position 115 to position 125 with each line in the second file and if there is a match, write the entire line ...
1
vote
1answer
637 views

Coloring the output of conky-cli in dwm

I've recently installed conky-cli and got it running on the upper bar in dwm with this simple command: conky | while read -r; do xsetroot -name "$REPLY"; done & And I wanted to get colored ...