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: Fri, 13 Jul 2007 21:41:46 -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

According to Chuck Simmons on 7/13/2007 9:31 PM:
> Since head and tail have similar functionality, they should respond to
> similar command line arguments in similar ways except that one command does
> the head of the file and one does the tail.

Sorry, but POSIX does not specify these two programs symmetrically.  POSIX
only specifies head to support positive numbers (so as a GNU extension, we
make the negative number count from the opposite direction).  On the other
hand, POSIX specifies tail's behavior for no sign, negative sign (both
from the end), and positive sign (from the beginning).

http://www.opengroup.org/onlinepubs/009695399/utilities/head.html
http://www.opengroup.org/onlinepubs/009695399/utilities/tail.html

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

Yes, it is unfortunate, but that is because POSIX merely standardized
existing practice, and 30 years of scripting would break if we were to
change it now.

> address@hidden:~$ tail --version
> tail (GNU coreutils) 5.93

This is an old version.  You may want to consider upgrading; the latest
stable version is 6.9.

- --
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

iD8DBQFGmEX184KuGfSFAYARAijVAJ9jG/A4tMrzmZ+sg0LG8EQOrip4YQCfQhkR
gAqFP8Cm6bI9j0y8cE9aizs=
=96ay
-----END PGP SIGNATURE-----




reply via email to

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