GNU bug report logs - #20928
cut (v. 8.21), using -f option with a single column

Previous Next

Package: coreutils;

Reported by: "Kuchta, Tomasz" <t.kuchta12 <at> imperial.ac.uk>

Date: Mon, 29 Jun 2015 15:19:02 UTC

Severity: normal

Tags: notabug

Done: Pádraig Brady <P <at> draigBrady.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 20928 in the body.
You can then email your comments to 20928 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#20928; Package coreutils. (Mon, 29 Jun 2015 15:19:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Kuchta, Tomasz" <t.kuchta12 <at> imperial.ac.uk>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 29 Jun 2015 15:19:02 GMT) Full text and rfc822 format available.

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

From: "Kuchta, Tomasz" <t.kuchta12 <at> imperial.ac.uk>
To: "bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>
Subject: cut (v. 8.21), using -f option with a single column
Date: Mon, 29 Jun 2015 08:18:25 +0000
Hello.

I’m not sure if this is a bug - I just wanted to let you know.
Thanks,
Tomek

——

When there is more than one column and we go beyond the number of columns with the -f option, the output is empty

$ echo "test1 test2" | cut -d' ' -f1
test1
$ echo "test1 test2" | cut -d' ' -f2
test2
$ echo "test1 test2" | cut -d' ' -f3

$

—— 

When there is only one column and we go beyond 1 with the -f option, the output remains the first column

$ echo "test1" | cut -d' ' -f1
test1
$ echo "test1" | cut -d' ' -f2
test1
$ echo "test1" | cut -d' ' -f3
test1

My setup:

$ cut --version
cut (GNU coreutils) 8.21
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David M. Ihnat, David MacKenzie, and Jim Meyering.

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 14.04.2 LTS
Release:	14.04
Codename:	trusty

Information forwarded to bug-coreutils <at> gnu.org:
bug#20928; Package coreutils. (Mon, 29 Jun 2015 15:32:02 GMT) Full text and rfc822 format available.

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

From: Pádraig Brady <P <at> draigBrady.com>
To: "Kuchta, Tomasz" <t.kuchta12 <at> imperial.ac.uk>, 20928 <at> debbugs.gnu.org
Subject: Re: bug#20928: cut (v. 8.21), using -f option with a single column
Date: Mon, 29 Jun 2015 16:31:00 +0100
tag 20928 notabug
close 20928
stop

On 29/06/15 09:18, Kuchta, Tomasz wrote:
> Hello.
> 
> I’m not sure if this is a bug - I just wanted to let you know.
> Thanks,
> Tomek
> 
> ——
> 
> When there is more than one column and we go beyond the number of columns with the -f option, the output is empty
> 
> $ echo "test1 test2" | cut -d' ' -f1
> test1
> $ echo "test1 test2" | cut -d' ' -f2
> test2
> $ echo "test1 test2" | cut -d' ' -f3
> 
> $
> 
> —— 
> 
> When there is only one column and we go beyond 1 with the -f option, the output remains the first column
> 
> $ echo "test1" | cut -d' ' -f1
> test1
> $ echo "test1" | cut -d' ' -f2
> test1
> $ echo "test1" | cut -d' ' -f3
> test1

That difference in behavior is there for compat reasons.
To induce the behavior you expect, you need the -s option.

thanks,
Pádraig.





Added tag(s) notabug. Request was from Pádraig Brady <P <at> draigBrady.com> to control <at> debbugs.gnu.org. (Mon, 29 Jun 2015 15:32:03 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 20928 <at> debbugs.gnu.org and "Kuchta, Tomasz" <t.kuchta12 <at> imperial.ac.uk> Request was from Pádraig Brady <P <at> draigBrady.com> to control <at> debbugs.gnu.org. (Mon, 29 Jun 2015 15:32:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#20928; Package coreutils. (Mon, 29 Jun 2015 15:38:02 GMT) Full text and rfc822 format available.

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

From: "Kuchta, Tomasz" <t.kuchta12 <at> imperial.ac.uk>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: "Kuchta, Tomasz" <t.kuchta12 <at> imperial.ac.uk>,
 "20928 <at> debbugs.gnu.org" <20928 <at> debbugs.gnu.org>
Subject: Re: bug#20928: cut (v. 8.21), using -f option with a single column
Date: Mon, 29 Jun 2015 15:37:29 +0000
Hi Pádraig,

Oh, I see - thanks for letting me know.

Kind regards,
Tomek

> On 29 Jun 2015, at 16:31, Pádraig Brady <P <at> draigBrady.com> wrote:
> 
> tag 20928 notabug
> close 20928
> stop
> 
> On 29/06/15 09:18, Kuchta, Tomasz wrote:
>> Hello.
>> 
>> I’m not sure if this is a bug - I just wanted to let you know.
>> Thanks,
>> Tomek
>> 
>> ——
>> 
>> When there is more than one column and we go beyond the number of columns with the -f option, the output is empty
>> 
>> $ echo "test1 test2" | cut -d' ' -f1
>> test1
>> $ echo "test1 test2" | cut -d' ' -f2
>> test2
>> $ echo "test1 test2" | cut -d' ' -f3
>> 
>> $
>> 
>> —— 
>> 
>> When there is only one column and we go beyond 1 with the -f option, the output remains the first column
>> 
>> $ echo "test1" | cut -d' ' -f1
>> test1
>> $ echo "test1" | cut -d' ' -f2
>> test1
>> $ echo "test1" | cut -d' ' -f3
>> test1
> 
> That difference in behavior is there for compat reasons.
> To induce the behavior you expect, you need the -s option.
> 
> thanks,
> Pádraig.
> 


Information forwarded to bug-coreutils <at> gnu.org:
bug#20928; Package coreutils. (Mon, 29 Jun 2015 16:06:02 GMT) Full text and rfc822 format available.

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

From: Stephane Chazelas <stephane.chazelas <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: Re: bug#20928: cut (v. 8.21), using -f option with a single column
Date: Mon, 29 Jun 2015 16:54:19 +0100
2015-06-29 16:31:00 +0100, Pádraig Brady:
[...]
> > When there is only one column and we go beyond 1 with the -f option, the output remains the first column
> > 
> > $ echo "test1" | cut -d' ' -f1
> > test1
> > $ echo "test1" | cut -d' ' -f2
> > test1
> > $ echo "test1" | cut -d' ' -f3
> > test1
> 
> That difference in behavior is there for compat reasons.

Yes, and that's required by POSIX
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html

> To induce the behavior you expect, you need the -s option.
[...]

-s suppresses the lines that don't have the field which is
different from outputting a blank field. Here, the OP more
likely wants:

paste -d ' ' - /dev/null | cut -d' ' -f3
(or awk -F'[ ]' '{print $3}')

$ printf '%s\n' a:b c d:e | cut -d: -f2
b
c
e
$ printf '%s\n' a:b c d:e | cut -sd: -f2
b
e
$ printf '%s\n' a:b c d:e | paste -d: - /dev/null | cut -d: -f2
b

e

-- 
Stephane





Information forwarded to bug-coreutils <at> gnu.org:
bug#20928; Package coreutils. (Mon, 29 Jun 2015 16:26:02 GMT) Full text and rfc822 format available.

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

From: Pádraig Brady <P <at> draigBrady.com>
To: Stephane Chazelas <stephane.chazelas <at> gmail.com>, 
 20928 <at> debbugs.gnu.org
Subject: Re: bug#20928: cut (v. 8.21), using -f option with a single column
Date: Mon, 29 Jun 2015 17:25:11 +0100
On 29/06/15 16:54, Stephane Chazelas wrote:
> 2015-06-29 16:31:00 +0100, Pádraig Brady:
> [...]
>>> When there is only one column and we go beyond 1 with the -f option, the output remains the first column
>>>
>>> $ echo "test1" | cut -d' ' -f1
>>> test1
>>> $ echo "test1" | cut -d' ' -f2
>>> test1
>>> $ echo "test1" | cut -d' ' -f3
>>> test1
>>
>> That difference in behavior is there for compat reasons.
> 
> Yes, and that's required by POSIX
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html
> 
>> To induce the behavior you expect, you need the -s option.
> [...]
> 
> -s suppresses the lines that don't have the field which is
> different from outputting a blank field. Here, the OP more
> likely wants:
> 
> paste -d ' ' - /dev/null | cut -d' ' -f3
> (or awk -F'[ ]' '{print $3}')
> 
> $ printf '%s\n' a:b c d:e | cut -d: -f2
> b
> c
> e
> $ printf '%s\n' a:b c d:e | cut -sd: -f2
> b
> e
> $ printf '%s\n' a:b c d:e | paste -d: - /dev/null | cut -d: -f2
> b
> 
> e

Good point. Or to better support field ranges:

$ printf '%s\n' a:b c d:e | sed 's/^[^:]*$/&:/' | cut -d: -f2-
b

e

cheers,
Pádraig.




Information forwarded to bug-coreutils <at> gnu.org:
bug#20928; Package coreutils. (Mon, 29 Jun 2015 16:46:02 GMT) Full text and rfc822 format available.

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

From: Stephane Chazelas <stephane.chazelas <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: Re: bug#20928: cut (v. 8.21), using -f option with a single column
Date: Mon, 29 Jun 2015 17:42:53 +0100
2015-06-29 17:25:11 +0100, Pádraig Brady:
[...]
> > $ printf '%s\n' a:b c d:e | paste -d: - /dev/null | cut -d: -f2
> > b
> > 
> > e
> 
> Good point. Or to better support field ranges:
> 
> $ printf '%s\n' a:b c d:e | sed 's/^[^:]*$/&:/' | cut -d: -f2-
> b
> 
> e
[...]

Maybe better as:

$ printf '%b\n' a:b 'P\0341draig' d:e | sed '/:/!s/$/:/' | cut -d: -f2-

so it also works on lines that contain invalid characters.

-- 
Stephane





Information forwarded to bug-coreutils <at> gnu.org:
bug#20928; Package coreutils. (Tue, 30 Jun 2015 08:04:02 GMT) Full text and rfc822 format available.

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

From: "Kuchta, Tomasz" <t.kuchta12 <at> imperial.ac.uk>
To: "20928 <at> debbugs.gnu.org" <20928 <at> debbugs.gnu.org>
Subject: Re: bug#20928: cut (v. 8.21), using -f option with a single column
Date: Tue, 30 Jun 2015 08:03:38 +0000
Pádraig, Stephane - thanks a lot for your help and quick response!
Tomek

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 28 Jul 2015 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 26 days ago.

Previous Next


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