You are not logged in.

#1 2008-12-01 02:09:21

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

How to apply inverse of head/tail

It seems as if I find myself wanting to extract the inverted selection of head or tail almost as often as I do the normal selection. Ie, I want to filter *out* the first or last n lines of some standard input. Is there a simple way to do this, aside from writing a short script to get the line count, then head/tailing off the complement of what I want? I wish head and tail had the grep equivalent of -v.

Offline

#2 2008-12-01 02:17:39

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: How to apply inverse of head/tail

From what I understand, the inverse of

head -n 25 file

would be

tail -n +25 file

and the inverse of

tail -n 25 file

would be

head -n -25 file

Is this what you want?


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#3 2008-12-01 03:01:30

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: How to apply inverse of head/tail

You can print address ranges with sed too.

# Print lines 10-20
sed -n '10,20p' filename

Might also want to look at «tac».

Offline

#4 2008-12-01 04:51:53

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

Re: How to apply inverse of head/tail

Thanks, rson. I was looking at the man pages and thought there was something along those lines syntax-wise, but I couldn't get it to work. Apparently I was misreading something. Thanks.

Offline

Board footer

Powered by FluxBB