GNU bug report logs - #14505
Bug in "cat" command

Previous Next

Package: coreutils;

Reported by: "Kakkar, Mayank (NSN - IN/Bangalore)" <mayank.kakkar <at> nsn.com>

Date: Wed, 29 May 2013 15:12:06 UTC

Severity: normal

Tags: moreinfo

Done: Assaf Gordon <assafgordon <at> gmail.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 14505 in the body.
You can then email your comments to 14505 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 bug-coreutils <at> gnu.org:
bug#14505; Package coreutils. (Wed, 29 May 2013 15:12:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Kakkar, Mayank (NSN - IN/Bangalore)" <mayank.kakkar <at> nsn.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Wed, 29 May 2013 15:12:07 GMT) Full text and rfc822 format available.

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

From: "Kakkar, Mayank (NSN - IN/Bangalore)" <mayank.kakkar <at> nsn.com>
To: "bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>
Subject: Bug in "cat" command
Date: Wed, 29 May 2013 11:57:49 +0000
[Message part 1 (text/plain, inline)]
Hi RHEL Team,

I was working with cat command and testing its functionality. I learnt in one of the manuals that if multiple files are specified, the contents of the files are concatenated in the output, but line numbering is restarted at 1 for each file. However in an experiment I found this not to be true.

[root <at> sai6 mayanktest]# ls -l aa bb
-rw-r--r-- 1 root root 10 May 29 17:15 aa
-rw-r--r-- 1 root root 22 May 29 17:18 bb

[root <at> sai6 mayanktest]# cat -b bb aa
     1  a
     2  b
     3  c
     4  d
     5  e


     6  f
     7  g
     8  h
     9  i
    10  j
    11  1
    12  2
    13  3
    14  4
15  5

Here, we can see that the numbering does not restarts with the new file contents.

I look forward to your response.

Regards
Mayank

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

Information forwarded to bug-coreutils <at> gnu.org:
bug#14505; Package coreutils. (Wed, 29 May 2013 15:29:01 GMT) Full text and rfc822 format available.

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

From: Eric Blake <eblake <at> redhat.com>
To: "Kakkar, Mayank (NSN - IN/Bangalore)" <mayank.kakkar <at> nsn.com>
Cc: 14505 <at> debbugs.gnu.org
Subject: Re: bug#14505: Bug in "cat" command
Date: Wed, 29 May 2013 09:26:40 -0600
[Message part 1 (text/plain, inline)]
tag 14505 needinfo
thanks

On 05/29/2013 05:57 AM, Kakkar, Mayank (NSN - IN/Bangalore) wrote:
> Hi RHEL Team,

This is the upstream coreutils list; if you were trying to reach RHEL
support, you should contact Red Hat per your contract with them.

> 
> I was working with cat command and testing its functionality. I learnt in one of the manuals that if multiple files are specified, the contents of the files are concatenated in the output, but line numbering is restarted at 1 for each file.

Thanks for the report.  What manual was this?  I don't see anything
implying that in the 'info cat' section of the official coreutils
manual, so this is likely a bug in downstream documentation rather than
an actual problem in coreutils.  But without knowing a URL of the faulty
documentation, we can't tell you where to redirect your report.

> Here, we can see that the numbering does not restarts with the new file contents.

coreutils' cat has never restarted numbering with new files. Maybe you
were thinking of 'sed --separate'?  At any rate, we're probably going to
close this report as not a bug, although I've left it open for a bit
longer in case you can tell us more details about what led you to
believe that renumbering from 1 was expected, in case there is something
we need to improve in coreutils' documentation.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Added tag(s) moreinfo. Request was from Eric Blake <eblake <at> redhat.com> to control <at> debbugs.gnu.org. (Wed, 29 May 2013 15:38:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#14505; Package coreutils. (Thu, 30 May 2013 04:42:03 GMT) Full text and rfc822 format available.

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

From: "Kakkar, Mayank (NSN - IN/Bangalore)" <mayank.kakkar <at> nsn.com>
To: ext Eric Blake <eblake <at> redhat.com>
Cc: "14505 <at> debbugs.gnu.org" <14505 <at> debbugs.gnu.org>
Subject: RE: bug#14505: Bug in "cat" command
Date: Thu, 30 May 2013 04:39:37 +0000
Hi Eric,

Thanks for your prompt reply. 

I am referring to the manual -> 'Sams teach yourself shell in 24 hours', which is authored by Sriranga Veeraraghavan. 

Following is example potrayed in that manual:

If multiple files are specified, the contents of the files are concatenated in the output, but line numbering is restarted at 1 for each file. As an illustration, the following command,

$ cat -b fruits users

produces the output

1 Fruit Price/lbs Quantity
2 Banana $0.89 100
3 Peach $0.79 65
4 Kiwi $1.50 22
5 Pineapple $1.29 35
6 Apple $0.99 78

1 ranga
2 vathsa
3 amma

So, this was what led me think this is a bug in cat command for RHEL 5.7, because this guy must have experimented it on the RHEL machine before printing it in the manual. 

Regards
Mayank
-----Original Message-----
From: ext Eric Blake [mailto:eblake <at> redhat.com] 
Sent: Wednesday, May 29, 2013 8:57 PM
To: Kakkar, Mayank (NSN - IN/Bangalore)
Cc: 14505 <at> debbugs.gnu.org
Subject: Re: bug#14505: Bug in "cat" command

tag 14505 needinfo
thanks

On 05/29/2013 05:57 AM, Kakkar, Mayank (NSN - IN/Bangalore) wrote:
> Hi RHEL Team,

This is the upstream coreutils list; if you were trying to reach RHEL
support, you should contact Red Hat per your contract with them.

> 
> I was working with cat command and testing its functionality. I learnt in one of the manuals that if multiple files are specified, the contents of the files are concatenated in the output, but line numbering is restarted at 1 for each file.

Thanks for the report.  What manual was this?  I don't see anything
implying that in the 'info cat' section of the official coreutils
manual, so this is likely a bug in downstream documentation rather than
an actual problem in coreutils.  But without knowing a URL of the faulty
documentation, we can't tell you where to redirect your report.

> Here, we can see that the numbering does not restarts with the new file contents.

coreutils' cat has never restarted numbering with new files. Maybe you
were thinking of 'sed --separate'?  At any rate, we're probably going to
close this report as not a bug, although I've left it open for a bit
longer in case you can tell us more details about what led you to
believe that renumbering from 1 was expected, in case there is something
we need to improve in coreutils' documentation.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


Information forwarded to bug-coreutils <at> gnu.org:
bug#14505; Package coreutils. (Thu, 30 May 2013 05:13:02 GMT) Full text and rfc822 format available.

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

From: Bob Proulx <bob <at> proulx.com>
To: "Kakkar, Mayank (NSN - IN/Bangalore)" <mayank.kakkar <at> nsn.com>
Cc: 14505 <at> debbugs.gnu.org
Subject: Re: bug#14505: Bug in "cat" command
Date: Wed, 29 May 2013 23:11:17 -0600
Kakkar, Mayank (NSN - IN/Bangalore) wrote:
> I am referring to the manual -> 'Sams teach yourself shell in 24
> hours', which is authored by Sriranga Veeraraghavan.

It isn't unusual for books to have bugs too.

> Following is example potrayed in that manual:
> 
> If multiple files are specified, the contents of the files are
> concatenated in the output, but line numbering is restarted at 1 for
> each file. As an illustration, the following command,
> 
> $ cat -b fruits users
> 
> produces the output
> 
> 1 Fruit Price/lbs Quantity
> 2 Banana $0.89 100
> 3 Peach $0.79 65
> 4 Kiwi $1.50 22
> 5 Pineapple $1.29 35
> 6 Apple $0.99 78
> 
> 1 ranga
> 2 vathsa
> 3 amma

That doesn't make sense because there is a blank line in the middle.
I think the book has an incorrect example.

> So, this was what led me think this is a bug in cat command for RHEL
> 5.7, because this guy must have experimented it on the RHEL machine
> before printing it in the manual.

The GNU cat documentation says:

  `-b'
  `--number-nonblank'
     Number all nonempty output lines, starting with 1.

Which talks about *output* lines not input lines.  Since cat is
conCATenating lines and emitting them to the output the output lines
are the ones that would be numbered.

If you really want to renumber each file then you can use a for loop.

  for f in fruits users; do
    cat -b "$f"
  done

But actually cat should never have added line numbering.  It
violates the principle that tools should be simple and do one thing
and do it well.  So it is sad that cat now has line numbering.  That
is just a bad thing.

Instead for line numbering I would use "nl".

  http://pubs.opengroup.org/onlinepubs/009695399/utilities/nl.html

Or I more likely for me I would use awk since it is standard and has
all of the needed functionality.  To do what you want, restarting
numbering for each file:

  $ awk '{print FNR, $0 }' fruits users

Or to do what nl (and cat too) does:

  $ awk '{print NR, $0 }' fruits users

Bob




Information forwarded to bug-coreutils <at> gnu.org:
bug#14505; Package coreutils. (Thu, 30 May 2013 05:23:01 GMT) Full text and rfc822 format available.

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

From: "Kakkar, Mayank (NSN - IN/Bangalore)" <mayank.kakkar <at> nsn.com>
To: ext Bob Proulx <bob <at> proulx.com>
Cc: "14505 <at> debbugs.gnu.org" <14505 <at> debbugs.gnu.org>
Subject: RE: bug#14505: Bug in "cat" command
Date: Thu, 30 May 2013 05:19:40 +0000
Hi Bob,

Thanks. That was very informative. 

Is http://www.proulx.com/~bob/ your site ? Quite interesting ... :) 

Regards
Mayank

-----Original Message-----
From: ext Bob Proulx [mailto:bob <at> proulx.com] 
Sent: Thursday, May 30, 2013 10:41 AM
To: Kakkar, Mayank (NSN - IN/Bangalore)
Cc: 14505 <at> debbugs.gnu.org
Subject: Re: bug#14505: Bug in "cat" command

Kakkar, Mayank (NSN - IN/Bangalore) wrote:
> I am referring to the manual -> 'Sams teach yourself shell in 24
> hours', which is authored by Sriranga Veeraraghavan.

It isn't unusual for books to have bugs too.

> Following is example potrayed in that manual:
> 
> If multiple files are specified, the contents of the files are
> concatenated in the output, but line numbering is restarted at 1 for
> each file. As an illustration, the following command,
> 
> $ cat -b fruits users
> 
> produces the output
> 
> 1 Fruit Price/lbs Quantity
> 2 Banana $0.89 100
> 3 Peach $0.79 65
> 4 Kiwi $1.50 22
> 5 Pineapple $1.29 35
> 6 Apple $0.99 78
> 
> 1 ranga
> 2 vathsa
> 3 amma

That doesn't make sense because there is a blank line in the middle.
I think the book has an incorrect example.

> So, this was what led me think this is a bug in cat command for RHEL
> 5.7, because this guy must have experimented it on the RHEL machine
> before printing it in the manual.

The GNU cat documentation says:

  `-b'
  `--number-nonblank'
     Number all nonempty output lines, starting with 1.

Which talks about *output* lines not input lines.  Since cat is
conCATenating lines and emitting them to the output the output lines
are the ones that would be numbered.

If you really want to renumber each file then you can use a for loop.

  for f in fruits users; do
    cat -b "$f"
  done

But actually cat should never have added line numbering.  It
violates the principle that tools should be simple and do one thing
and do it well.  So it is sad that cat now has line numbering.  That
is just a bad thing.

Instead for line numbering I would use "nl".

  http://pubs.opengroup.org/onlinepubs/009695399/utilities/nl.html

Or I more likely for me I would use awk since it is standard and has
all of the needed functionality.  To do what you want, restarting
numbering for each file:

  $ awk '{print FNR, $0 }' fruits users

Or to do what nl (and cat too) does:

  $ awk '{print NR, $0 }' fruits users

Bob




Information forwarded to bug-coreutils <at> gnu.org:
bug#14505; Package coreutils. (Tue, 23 Oct 2018 22:41:02 GMT) Full text and rfc822 format available.

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

From: Assaf Gordon <assafgordon <at> gmail.com>
To: "14505 <at> debbugs.gnu.org" <14505 <at> debbugs.gnu.org>
Subject: Re: bug#14505: Bug in "cat" command
Date: Tue, 23 Oct 2018 16:39:57 -0600
close 14505
stop

(triaging old bugs)

On 29/05/13 11:19 PM, Kakkar, Mayank (NSN - IN/Bangalore) wrote:
> 
> Thanks. That was very informative.
> 

With no further comments, I'm closing this bug.

-assaf





bug closed, send any further explanations to 14505 <at> debbugs.gnu.org and "Kakkar, Mayank (NSN - IN/Bangalore)" <mayank.kakkar <at> nsn.com> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 23 Oct 2018 22:41:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 21 Nov 2018 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 272 days ago.

Previous Next


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