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?

nucandrei
  • 195
  • 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 '14 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 '14 at 07:01

1 Answers1

9

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.

cuonglm
  • 153,898
  • Thank you. I read the documentation, but I missed those details. I should read more carefully next time. – nucandrei Sep 26 '14 at 09:13