GNU bug report logs - #6605
+N lines broken with /usr/bin/tail (GNU coreutils) 7.4

Previous Next

Package: coreutils;

Reported by: Forest Oakwater <forest_oakwater <at> yahoo.com>

Date: Sat, 10 Jul 2010 16:30:04 UTC

Severity: normal

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 6605 in the body.
You can then email your comments to 6605 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6605; Package coreutils. (Sat, 10 Jul 2010 16:30:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Forest Oakwater <forest_oakwater <at> yahoo.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sat, 10 Jul 2010 16:30:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Forest Oakwater <forest_oakwater <at> yahoo.com>
To: bug-coreutils <at> gnu.org
Subject: +N lines broken with /usr/bin/tail (GNU coreutils) 7.4
Date: Sat, 10 Jul 2010 03:50:32 -0700 (PDT)
[Message part 1 (text/plain, inline)]
Using this data file:
dad <at> elrond:~/backgrounds/frazetta$ cat data.txt
line 1
line 2
line 3
line 4

and this command:
dad <at> elrond:~/backgrounds/frazetta$ /usr/bin/tail +2 data.txt
/usr/bin/tail: cannot open `+2' for reading: No such file or directory
==> data.txt <==
line 1
line 2
line 3
line 4

Output was incorrect.  The manpage and builtin help text both state:

dad <at> elrond:~/backgrounds/frazetta$ /usr/bin/tail --help
...
  -n, --lines=N            output the last N lines, instead of the last 10;
                           or use +N to output lines starting with the Nth
...

According to the documentation (and my previous experience shell scripting) It should have printed the tail of data.txt starting with the 2nd line, like this:
line 2
line 3
line 4

Looks like it just needs a little code near the getopt() call (or however the command line is parsed) to recognize "+" as an option indicator.

This is useful for example to implement a stack:
function pop
{
    FILENAME=`head -1 data.file`
    tail +2 data.file > data.file.tmp
    mv data.file.tmp data.file
}

function push
{
    echo "$FILENAME" > data.file.line1
    cat data.file.line1 data.file > data.file.tmp
    mv data.file.tmp data.file
}

Thanks for your attention.




      
[Message part 2 (text/html, inline)]

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6605; Package coreutils. (Sat, 10 Jul 2010 20:07:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Davide Brini <dave_br <at> gmx.com>
To: bug-coreutils <at> gnu.org
Subject: Re: bug#6605: +N lines broken with /usr/bin/tail (GNU coreutils) 7.4
Date: Sat, 10 Jul 2010 20:53:30 +0100
On Sat, 10 Jul 2010 03:50:32 -0700 (PDT) Forest Oakwater
<forest_oakwater <at> yahoo.com> wrote:

> Using this data file:
> dad <at> elrond:~/backgrounds/frazetta$ cat data.txt
> line 1
> line 2
> line 3
> line 4
> 
> and this command:
> dad <at> elrond:~/backgrounds/frazetta$ /usr/bin/tail +2 data.txt
> /usr/bin/tail: cannot open `+2' for reading: No such file or directory
> ==> data.txt <==
> line 1
> line 2
> line 3
> line 4
> 
> Output was incorrect.  The manpage and builtin help text both state:
> 
> dad <at> elrond:~/backgrounds/frazetta$ /usr/bin/tail --help
> ...
>   -n, --lines=N            output the last N lines, instead of the last
> 10; or use +N to output lines starting with the Nth
> ...

This is not what you did. You did "tail +2", whereas the man says you
should do "tail -n +2", or "tail --lines=+2". If you want to output the
last N lines, rather than starting from the Nth, you'd do "tail -n 2" or
"tail --lines=2".

The "tail +2" syntax is obsolete; probably the recent versions of coreutils
(which 7.4 is not, anyway) dropped support for it.

-- 
D.




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6605; Package coreutils. (Mon, 12 Jul 2010 18:47:02 GMT) Full text and rfc822 format available.

Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> CS.UCLA.EDU>
To: forest_oakwater <at> yahoo.com
Cc: bug-coreutils <at> gnu.org
Subject: Re: bug#6605: +N lines broken with /usr/bin/tail (GNU coreutils) 7.4
Date: Mon, 12 Jul 2010 11:46:55 -0700
On 07/10/10 12:53, Davide Brini wrote:

> The "tail +2" syntax is obsolete; probably the recent versions of coreutils
> (which 7.4 is not, anyway) dropped support for it.

It's not just obsolete: it's incompatible with POSIX 1003.1-2001,
which is why it was dropped a while ago.  You can bring back
support for "tail +2" by setting _POSIX2_VERSION=199209 in
your environment; this is documented in the coreutils manual.
But it's probably better to update those dusty old shell scripts
to use the POSIX-specified syntax.




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6605; Package coreutils. (Thu, 15 Jul 2010 20:35:02 GMT) Full text and rfc822 format available.

Message #14 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Forest Oakwater <forest_oakwater <at> yahoo.com>
To: Paul Eggert <eggert <at> CS.UCLA.EDU>
Cc: bug-coreutils <at> gnu.org
Subject: Re: bug#6605: +N lines broken with /usr/bin/tail (GNU coreutils) 7.4
Date: Thu, 15 Jul 2010 13:34:50 -0700 (PDT)
[Message part 1 (text/plain, inline)]
Paul,

Thank you for the information.  Would you consider updating the builtin documentation and man page to match the behavior of the program?

Also, do you know of an efficient POSIX way to filter out the first N lines of a text file?

# inefficient?
head -N datafile > datafile.head
diff datafile.head datafile |grep '^>' |cut -c3- > datafile.new
mv datafile.new datafile

Thanks,
Forest


--- On Mon, 7/12/10, Paul Eggert <eggert <at> CS.UCLA.EDU> wrote:

From: Paul Eggert <eggert <at> CS.UCLA.EDU>
Subject: Re: bug#6605: +N lines broken with /usr/bin/tail (GNU coreutils) 7.4
To: forest_oakwater <at> yahoo.com
Cc: bug-coreutils <at> gnu.org
Date: Monday, July 12, 2010, 2:46 PM

On 07/10/10 12:53, Davide Brini wrote:

> The "tail +2" syntax is obsolete; probably the recent versions of coreutils
> (which 7.4 is not, anyway) dropped support for it.

It's not just obsolete: it's incompatible with POSIX 1003.1-2001,
which is why it was dropped a while ago.  You can bring back
support for "tail +2" by setting _POSIX2_VERSION=199209 in
your environment; this is documented in the coreutils manual.
But it's probably better to update those dusty old shell scripts
to use the POSIX-specified syntax.



      
[Message part 2 (text/html, inline)]

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6605; Package coreutils. (Thu, 15 Jul 2010 21:16:01 GMT) Full text and rfc822 format available.

Message #17 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Forest Oakwater <forest_oakwater <at> yahoo.com>
Cc: bug-coreutils <at> gnu.org
Subject: Re: bug#6605: +N lines broken with /usr/bin/tail (GNU coreutils) 7.4
Date: Thu, 15 Jul 2010 15:15:08 -0600
Forest Oakwater wrote:
> Thank you for the information.  Would you consider updating the
> builtin documentation and man page to match the behavior of the
> program?

You say that like it doesn't match now.  :-)  But it does.  You even
quoted the important parts in your original message.

You wrote:
>  -n, --lines=N            output the last N lines, instead of the last 10;
>                           or use +N to output lines starting with the Nth

So I know you have an older version of the program with the older
version of the online docs.  But those are strictly correct!  The
confusion you are experiencing comes from the -n using 'n' and the
--lines=N using 'N'.  Some time in the last while there was another
discussion of this (it will be in the archive but I don't have time to
look) we decided to change this to K to make it more obvious.  The
current online documentation says:

    -n, --lines=K            output the last K lines, instead of the last 10;
                             or use -n +K to output lines starting with the Kth
  If the first character of K (the number of bytes or lines) is a `+',

We thought it was more clear to use 'K' instead to avoid any confusion
of N with -n.  But as you can see with K it still says about the same
thing.  If you want to use a +NUM then you need to say 'tail -n +2' or
some such.  So the older documentation is correct and the newer
documentation is both correct and more helpful.

> Also, do you know of an efficient POSIX way to filter out the first
> N lines of a text file?

I personally like sed for this.

  sed 1,2d FILE

Or:

  sed -n '3,$p' FILE

> # inefficient?
> head -N datafile > datafile.head
> diff datafile.head datafile |grep '^>' |cut -c3- > datafile.new
> mv datafile.new datafile

Please, my eyes, the pain! :-}

Bob




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6605; Package coreutils. (Thu, 15 Jul 2010 21:21:02 GMT) Full text and rfc822 format available.

Message #20 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> CS.UCLA.EDU>
To: Forest Oakwater <forest_oakwater <at> yahoo.com>
Cc: bug-coreutils <at> gnu.org
Subject: Re: bug#6605: +N lines broken with /usr/bin/tail (GNU coreutils) 7.4
Date: Thu, 15 Jul 2010 14:20:29 -0700
On 07/15/10 13:34, Forest Oakwater wrote:
> Would you consider updating the builtin
> documentation and man page to match the behavior of the program?

That's already the case, surely.

> Also, do you know of an efficient POSIX way to filter out the first N
> lines of a text file?

"tail -n +51", "sed 1,50d", "awk '50 < NR'"; take your pick.




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6605; Package coreutils. (Thu, 15 Jul 2010 21:42:02 GMT) Full text and rfc822 format available.

Message #23 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Davide Brini <dave_br <at> gmx.com>
To: bug-coreutils <at> gnu.org
Subject: Re: bug#6605: +N lines broken with /usr/bin/tail (GNU coreutils) 7.4
Date: Thu, 15 Jul 2010 22:28:53 +0100
On Thu, 15 Jul 2010 13:34:50 -0700 (PDT) Forest Oakwater
<forest_oakwater <at> yahoo.com> wrote:

> Paul,
> 
> Thank you for the information.  Would you consider updating the builtin
> documentation and man page to match the behavior of the program?

It *is* correct. Nowhere it says that you can use "tail -2" or "tail +2".

Instead it says that you should use

"tail -n N", or "tail --lines=N" (or +N if you want from line N).

> Also, do you know of an efficient POSIX way to filter out the first N
> lines of a text file?
> 
> # inefficient?
> head -N datafile > datafile.head
> diff datafile.head datafile |grep '^>' |cut -c3- > datafile.new
> mv datafile.new datafile

Dozens, all probably just as efficient as using tail -n +N.

-- 
D.




Reply sent to Bob Proulx <bob <at> proulx.com>:
You have taken responsibility. (Thu, 25 Aug 2011 05:41:01 GMT) Full text and rfc822 format available.

Notification sent to Forest Oakwater <forest_oakwater <at> yahoo.com>:
bug acknowledged by developer. (Thu, 25 Aug 2011 05:41:02 GMT) Full text and rfc822 format available.

Message #28 received at 6605-done <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Forest Oakwater <forest_oakwater <at> yahoo.com>
Cc: 6605-done <at> debbugs.gnu.org
Subject: Re: bug#6605: +N lines broken with /usr/bin/tail (GNU coreutils) 7.4
Date: Wed, 24 Aug 2011 23:38:13 -0600
> http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6605

It has been a year since any feedback has been provided on this issue
in the bug tracking system.  I believe that the discussion logged so
far was sufficient to fully resolve the issue.  Therefore I am closing
this bug.  Feel free to follow-up with more information if desired.

Bob




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 22 Sep 2011 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 280 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.