GNU bug report logs - #39951
tail -n +NUM is not working properly

Previous Next

Package: coreutils;

Reported by: Dimitris Moraitidis <dimitris.moraitidis <at> gmail.com>

Date: Fri, 6 Mar 2020 15:30:02 UTC

Severity: normal

To reply to this bug, email your comments to 39951 AT debbugs.gnu.org.

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

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


Report forwarded to bug-coreutils <at> gnu.org:
bug#39951; Package coreutils. (Fri, 06 Mar 2020 15:30:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Dimitris Moraitidis <dimitris.moraitidis <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Fri, 06 Mar 2020 15:30:02 GMT) Full text and rfc822 format available.

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

From: Dimitris Moraitidis <dimitris.moraitidis <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: tail -n +NUM is not working properly
Date: Fri, 6 Mar 2020 10:42:15 +0100
[Message part 1 (text/plain, inline)]
Hey there,

tail -n + NUM does not return the desired output. +NUM starts from the top
of the file, not from the bottom.

So for example, given the following file:

>this
>is
>an
>example
>file
>each
>word
>represents
>a
>line

and executing tail -n +3 example, I am getting

>example
>file
>each
>word
>represents
>a
>line

instead of


>this
>is
>an
>example
>file
>each
>word

I am using *tail (GNU coreutils) 8.28 *in latest ubuntu 18.04 LTS

Thanks in advance for looking into this :)

-- 
// Moraitidis D. Dimitris,
// Athens University of Economics and Business (AUEB)
// Department of Informatics
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#39951; Package coreutils. (Fri, 06 Mar 2020 17:33:01 GMT) Full text and rfc822 format available.

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

From: Michael Speer <knomenet <at> gmail.com>
To: Dimitris Moraitidis <dimitris.moraitidis <at> gmail.com>
Cc: 39951 <at> debbugs.gnu.org
Subject: Re: bug#39951: tail -n +NUM is not working properly
Date: Fri, 6 Mar 2020 12:32:04 -0500
[Message part 1 (text/plain, inline)]
you want the `head` of the file sans the last few lines, rather than the
`tail` of the file sans the first few.

from the man page for tail

>      -n, --lines=[+]NUM
>              output the last NUM lines, instead of the last 10; or use -n
+NUM to output starting with line NUM

> use -n +NUM to output starting with line NUM

so content after the given number of lines

from the man page for head

>       -n, --lines=[-]NUM
>              print the first NUM lines instead of the first 10; with the
leading '-', print all but the last NUM lines of each file

> with the leading '-', print all but the last NUM lines of each file

this is the one you want.

the functionality can seem a little backwards, but makes sense if you
consider tail giving data relative to the end and head relative to the
start.
each then has an option to act relative to the other side of the document.


On Fri, Mar 6, 2020 at 10:31 AM Dimitris Moraitidis <
dimitris.moraitidis <at> gmail.com> wrote:

> Hey there,
>
> tail -n + NUM does not return the desired output. +NUM starts from the top
> of the file, not from the bottom.
>
> So for example, given the following file:
>
> >this
> >is
> >an
> >example
> >file
> >each
> >word
> >represents
> >a
> >line
>
> and executing tail -n +3 example, I am getting
>
> >example
> >file
> >each
> >word
> >represents
> >a
> >line
>
> instead of
>
>
> >this
> >is
> >an
> >example
> >file
> >each
> >word
>
> I am using *tail (GNU coreutils) 8.28 *in latest ubuntu 18.04 LTS
>
> Thanks in advance for looking into this :)
>
> --
> // Moraitidis D. Dimitris,
> // Athens University of Economics and Business (AUEB)
> // Department of Informatics
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#39951; Package coreutils. (Fri, 06 Mar 2020 17:36:03 GMT) Full text and rfc822 format available.

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

From: Bernhard Voelker <mail <at> bernhard-voelker.de>
To: Dimitris Moraitidis <dimitris.moraitidis <at> gmail.com>, 39951 <at> debbugs.gnu.org
Subject: Re: bug#39951: tail -n +NUM is not working properly
Date: Fri, 6 Mar 2020 18:35:24 +0100
On 3/6/20 10:42 AM, Dimitris Moraitidis wrote:
> Hey there,
> 
> tail -n + NUM does not return the desired output. +NUM starts from the top
> of the file, not from the bottom.
> 
> So for example, given the following file:
> 
>> this
>> is
>> an
>> example
>> file
>> each
>> word
>> represents
>> a
>> line
> 
> and executing tail -n +3 example, I am getting
> 
>> example
>> file
>> each
>> word
>> represents
>> a
>> line
> 
> instead of
> 
> 
>> this
>> is
>> an
>> example
>> file
>> each
>> word
> 
> I am using *tail (GNU coreutils) 8.28 *in latest ubuntu 18.04 LTS
> 
> Thanks in advance for looking into this :)

Isn't this exactly what tail(1) is support to do when the user explicitly
passes the '+' sign to the number?

  $ tail --help | grep -A1 -- --lines
    -n, --lines=[+]NUM       output the last NUM lines, instead of the last 10;
                               or use -n +NUM to output starting with line NUM

Also POSIX says so:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tail.html

Have a nice day,
Berny




This bug report was last modified 5 years and 100 days ago.

Previous Next


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