rone: (Default)
[personal profile] rone

I want to run a command that will give me the contents of a file, except for the last two lines.  I know that tail -2 filename will give me the last two lines of a file, and head -2 filename will give me the first two lines of a file.  Now, tail +2 filename will give me contents of a file, starting with line 2.  It's not a symmetrical option, but i can at least work with that.  However, the head command lacks this elegant mode; otherwise, i would infer that head +3 filename would give me what i want.  Is there a simple command that can do what i want?  I figure i can implement this in some fugly perl script, but that is not the damn point.

Date: 2008-12-05 08:25 am (UTC)
From: [identity profile] dagbrown.livejournal.com

Heh, I just thought of an evil one.

tac foo | tail +2 | tac

Date: 2008-12-05 08:27 am (UTC)
ext_8707: Taken in front of Carnegie Hall (bofh)
From: [identity profile] ronebofh.livejournal.com
Heh, a friend elsewhere suggested that one, too. Only a weenie OS like Linux would have a utility like tac.

Date: 2008-12-05 08:33 am (UTC)
From: [identity profile] dagbrown.livejournal.com
It actually had its genesis in a bunch of other weenies: the wacky land of BSD ("cat came back from Berkeley waving flags").

Date: 2008-12-05 07:11 pm (UTC)
ext_8707: Taken in front of Carnegie Hall (imminent destruction)
From: [identity profile] ronebofh.livejournal.com
Ironic that FreeBSD doesn't have it anymore...

Date: 2008-12-05 07:55 pm (UTC)
From: [identity profile] glaucon.livejournal.com
tac!
fucking awesome!

this is my new favorite unix command.
(replacing "yes")



Date: 2008-12-05 03:33 pm (UTC)
ext_243: (bee weapon)
From: [identity profile] xlerb.livejournal.com
I was going to suggest that, but with tail -r instead of tac (and the intimation that some systems may provide that functionality by a different means).

Profile

rone: (Default)
entombed in the shrine of zeroes and ones

December 2022

S M T W T F S
    123
45678910
11121314151617
18192021222324
252627282930 31

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 25th, 2025 05:18 am
Powered by Dreamwidth Studios