bug#23922: cut fails for non-delimited input lines with -f 2

2016-07-08 Thread Jens Mueller
Hi,

I'd like to report the following behavior of cut.
I execute

$ echo "abc" | cut -f 2 -d " "

and I expect the empty line as output but you get "abc\n".
I believe the empty line is correct because I selected the second
field which is empty.
If you select the 3rd field

$ echo "abc cde" | cut -f 3 -d " "

it outputs the empty line and works as expected which supports my
reasoning.

I am running Debian with

$ cut --version | head -1
cut (GNU coreutils) 8.25

Jens





bug#23922: cut fails for non-delimited input lines with -f 2

2016-07-08 Thread Assaf Gordon
tag 23922 notabug
close 23922
stop

Hello Jens,

> On Jul 8, 2016, at 19:05, Jens Mueller  wrote:
> 
> $ echo "abc" | cut -f 2 -d " "
> 
> and I expect the empty line as output but you get "abc\n".

It is not a bug, but correct behavior (though perhaps unexpected) to print 
"abc" in this case.

The POSIX standard says (at
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html):
"-s
Suppress lines with no delimiter characters, when used with the -f option. 
Unless specified, lines with no delimiters shall be passed through untouched."

In GNU cut's help screen (cut --help) shows:
  -s, --only-delimiteddo not print lines not containing delimiters

The following will demonstrate:

  $ printf "abc\nd f\n" | cut -f2 -d " "
  abc
  f

  $ printf "abc\nd f\n" | cut -s -f2 -d " "
  f

As such, I'm closing this bug report - but discussion can continue by replying 
to this thread.

regards,
  - assaf