sed clarification

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

sed clarification

vamsi krishna
I am using below unix script to delete first line in all files with extension .log in a directory

cd /home/edw/input
for file in *.log
do
   sed -n '2,$p' $file > $file
done

Instead of deleting first line in the script,the above script is creating one more file with zero bytes.
Reply | Threaded
Open this post in threaded view
|

Re: sed clarification

Guru
Administrator
This post was updated on .
 When you try to update your source file itself, use the -i option which
updates the file in-place:
sed -i -n '2,$p' $file > $file

If, in case, your sed does not have -i option, do it like this(saving in
temporary file and renaming it):
sed -n '2,$p' $file > temp
mv temp $file
Reply | Threaded
Open this post in threaded view
|

Re: sed clarification

vamsi
Thanks for your input