sed change entire line

Here I use sed to replace the entire 2nd line in a lot of files with a new 2nd line.

The shell script:

for fle in `ls *.msg`
do
    # copy file first so as can keep permissions and ownership identical
    cp -p $fle test_$fle
    # replace entire 2nd line with a new 2nd line
    sed -f t.sed $fle > test_$fle
done

Which calls this sed command file, named t.sed:

2c\
\To: dummy.email@me.com

The result is that the 2nd line in each file reads:

To: dummy.email@me.com
June 8, 2011

Leave a Reply

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