coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why cut treats one column input differently for out-of-range field s


From: Pádraig Brady
Subject: Re: Why cut treats one column input differently for out-of-range field spec?
Date: Wed, 17 Jan 2018 07:57:31 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 17/01/18 06:16, Peng Yu wrote:
> Hi,
> 
> If there is only one column in the input, then an out-of-range field
> spec will result in the print of the whole line.
> 
> $ cut -f 3 <<< $'a' | xxd
> 0000000: 610a                                     a.
> 
> Otherwise, an empty string is printed.
> 
> $ cut -f 3 <<< $'a\tb' | xxd
> 0000000: 0a                                       .
> 
> This is counter-intuitive. I think that one-field input should not be
> treated specially. It should still result in no output for an
> out-of-range field spec.
> 
> Is there a strong reason why `cut` should treat one-field input
> different? (What if users do want empty string be printed for
> out-of-range field even for one-field input?) Or this should be
> considered as a bug?

It's expected albeit confusing behavior, documented at:
http://www.pixelbeat.org/docs/coreutils-gotchas.html#cut

Essentially cut passes lines without delimiters through unchanged by default

cheers,
Pádraig.



reply via email to

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