sed = search and …..

source : http://lowfatlinux.com/linux-sed.html
sed does not change the input file
“The general forms of the sed command are as follows:

Substitution sed ‘s///g’
Deletion sed ‘,d’

Let’s start with a substitution example. If you want to change all occurrences of lamb to ham in the poem.txt file in the grep example, enter this:

sed ‘s/lamb/ham/g’ poem.txt
Mary had a little ham
Mary fried a lot of spam
Jack ate a Spam sandwich
Jill had a ham spamwich

In the quoted string, the “s” means substitute, and the “g” means make a global change. You can also leave off the “g” (to change only the first occurrence on each line) or specify a number instead (to change the first n occurrences on each line).

sed ‘2,3d’ poem.txt
Mary had a little lamb
Jill had a lamb spamwich

This example will delete starting at line 1, up to and including the next line containing Jack:

sed ‘1,/Jack/d’ poem.txt
Jill had a lamb spamwich

sed ‘s/lamb$/ham/g’ poem.txt > new.file

Since we directed output to a file, sed didn’t print anything on the screen. If you look at the contents of new.file it will show these lines:

Mary had a little ham
Mary fried a lot of spam
Jack ate a Spam sandwich
Jill had a lamb spamwich

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.