2010/6/22

Usage of sed II: insert a line into files

You can insert a new line before the pattern with the "i" command:
insert "testtest" into 100 line in a.txt
sed -i '100i testtest' a.txt

Append a line with 'a'
The "a" command appends a line after the range or pattern. This example will add a line after every line with "WORD:"
exchange insert 'i' to 'a'
insert "testtest" into 100 line in a.txt, you can also rewrite with a in
sed -i '99a testtest' a.txt

To fin any number in file, and then replace to "asdf"
sed -n '/EXPORTFNAME/s/[0-9][0-9]*/asdf/p' FILE