sed question

Hi,

When deleting lines using sed, as i understand the lines are redirected to the standard output. What i'm unclear about is how to actually modify the file?

If I write the command sed '1,2d' test it will display lines one and 2 onto the screen however the file is not modified? I think my confusion lies somewhere in the redirection of things but cannot seem to grasp it!!!!

Any ideas?

Thanks

Michael

Hmmm i think i have answered my own question, what i was missing was the >> operator

sed '1,2d' >> test test.

Sorry about that!

Using SED you cannot modify the source file.
sed '1,2d' test > temp # It will delete first and second line and display the rest of file
mv temp test

Thanks,

do you know how to wrap the ' ' around a sed argument when passing to a varible?

i.e.

arg1=$1
file=$2

sed $arg1 $file > temp
mv temp $file

so if i run, myscript '1,2d' newphone.list it doesn't work?

i've echo'd $arg1 to the screen and i get 1,2d instead of '1,2d'

thanks

myscript '1,2d' newphone.list # this will work
Above script should work. If you get some error show us the error or what output you get.

I always just redirect the output of sed to a temp file and then copy or move the temp file back over original I changed.