[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Removeing N lines from a file



Lance Hoffmeyer:
> How can I use gawk or some other program to remove a number of lines
> from a text file.  Initially, I only need to delete the top 10 lines
> from a file

As others already wrote, use 
	tail +11

> but it might be useful to know how to delete lines from any part of the
> file.

Well, since you are asking about awk, you might use something like:

  $NR > 10 {print}

to remove just the first 10 lines, or if you need to get fancier

  sin($NR) > 0 {print}

which will output those lines for which the sine of the line number is
positive.

> The top 10 lines from each of these files vary in what they may contain
> so I need to indiscriminately delete them.

Hmm, I don't know what your files look like, but it may be worthwhile to
use a proper pattern in gawk or perl, to guard against seemingly innocuous
changes in the input.


Jiri
-- 
<jiri@baum.com.au>
We'll know the future has arrived when every mailer transparently
quotes lines that begin with "From ", but no-one remembers why.


Reply to: