[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#20928: cut (v. 8.21), using -f option with a single column
From: |
Stephane Chazelas |
Subject: |
bug#20928: cut (v. 8.21), using -f option with a single column |
Date: |
Mon, 29 Jun 2015 16:54:19 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
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