Sed question

Giorgos Keramidas keramida at
Sun Dec 21 05:42:59 UTC 2008

On Sat, 20 Dec 2008 21:34:10 -0800, Gary Kline <kline at> wrote:
> how can i delete, say, lines 8,9,and 10 from 200 files
> using sed?  Is it
> sed '8,10d'< file> newfile
> or is there a better way?

Use in-place editing:

  keramida at kobe:/tmp$ cat -n foo
       1  foo
       2  bar
       3  baz
  keramida at kobe:/tmp$ sed -i '' -e '2d' foo
  keramida at kobe:/tmp$ cat -n foo
       1  foo
       2  baz
  keramida at kobe:/tmp$

Look at the manpage of sed for more details about the -i option, and
consider using backup files while you are running tests.  In-place
editing is very cool, but it can also make changes that are difficult
to recover from.

More information about the freebsd-questions mailing list