bug-coreutils
[Top][All Lists]
Advanced

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

Re: head and tail


From: Eric Blake
Subject: Re: head and tail
Date: Sat, 14 Jul 2007 07:23:54 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070604 Thunderbird/2.0.0.4 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Please keep replies on the list, so that others may benefit.

According to Chuck Simmons on 7/13/2007 10:14 PM:
> Eric --
> 
> Wow, nice write up.  Thanks.
> 
> Any chance that the man page should be updated to document the '+1'
> behavior?  Oh.  It is documented.  It just isn't documented in roughly
> the same place as it is documented in the 'head' man page.

Hey, documentation bugs count as bugs too - so maybe someone can check in
a patch to make this asymmetry between head and tail more prominent in the
docs.

>  So, this is
> sorta user interface testing.  What this user did was:  I glanced at the
> tail document quickly and didn't see anything obvious.  I glanced at the
> head document and saw the -n -1 paragraph that documented the behavior I
> wanted.  I went back to the tail document and looked at the -n
> paragraph, and concluded tail didn't do what I want.  Moving the
> relevant paragraph up in the document might be useful.
> 
> As you already know, my man version is:
> tail 5.93                          May 2006                           
> TAIL(1)
> 
> 
> Hmmm... I wonder if ubuntu would update this stuff...  Hmmm...  Synaptic
> says the latest version of coreutils is 5.93-5ubuntu4...

That just means that ubuntu is behind the curve in selecting newer stable
upstream packages.  You could always build the pristine upstream tarball
[1], if you are willing to do it yourself instead of relying on ubuntu.
Meanwhile, the more people that complain to the distro that their version
is out of date, the more likely they are to package a newer version.

[1] http://article.gmane.org/gmane.comp.gnu.coreutils.announce/40

> > So, what you want is:
> > 
> > first portion of file: head -n 1
> > last portion of file: tail -n 1
> > all but first portion of file: head -n -1
> > all but last portion of file: tail -n +1

I think I worded that a bit poorly.  Here's a better attempt, with an
actual example:

$ cat >list <<EOF
> a
> b
> c
> d
> e
> f
> g
> EOF
$ head -n 2 list # first two lines
a
b
$ head -n -2 list # all but last two lines
a
b
c
d
e
$ tail -n 2 list # last two lines
f
g
$ tail -n +3 list # start at third line, getting all but first two lines
c
d
e
f
g

Note that tail -n +num is one-based, while head -n -num is 0-based, in
deciding how many lines at the excluded side of the file are skipped.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGmM5p84KuGfSFAYARAh6LAKDTfCDWADirAiBnSNNXcLQ7iUuYCgCgmGTS
60P4mS1grOXwiqCODLxgfQg=
=4ym7
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]