[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to remove a specific line in a file
From: |
Bob Proulx |
Subject: |
Re: How to remove a specific line in a file |
Date: |
Tue, 1 May 2007 10:14:13 -0600 |
User-agent: |
Mutt/1.5.9i |
Matthew Woehlke wrote:
> $ sed -e '5d' -e '/FOO/d' -e '5,7d' myfile > mynewfile
>
> Note that redirecting output to an input file is not recommended (you
> might end up truncating the file, for example).
You almost certainly would.
> If you need to replace the file, it is best to write to a temporary
> file and use e.g. 'mv mynewfile myfile' when you are done.
Check out the newish sed option --in-place. It does what you want.
$ sed --in-place $SEDCOMMAND $SOMEFILE
This is available in sed version 4 and later.
Bob