6

I executed

cut -d '~' -f 2 on input

RSC
AED
FCB
A~RS

and I obtained

RSC
AED
FCB
RS

I realized that cut will return entire line if the delimiter does not exist. It is that true?

2
  • Why not try it and see? Run the command cut -d '~' -f 2 at a prompt, type in some lines and see what gets printed.
    – Perry
    Sep 27, 2014 at 18:52
  • As specified in question I ran some examples and I realized that behavior. I wanted to be sure that I was right.
    – nucandrei
    Sep 29, 2014 at 7:01

1 Answer 1

8

It's true. POSIX define cut -f option as:

-f list

Cut based on a list of fields, assumed to be separated in the file by a delimiter character (see -d). Each selected field shall be output. Output fields shall be separated by a single occurrence of the field delimiter character. Lines with no field delimiters shall be passed through intact, unless -s is specified. It shall not be an error to select fields not present in the input line.

and this repeated again in -s:

-s

Suppress lines with no delimiter characters, when used with the -f option. Unless specified, lines with no delimiters shall be passed through untouched.

1
  • Thank you. I read the documentation, but I missed those details. I should read more carefully next time.
    – nucandrei
    Sep 26, 2014 at 9:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .