Linux Cut Command – Does Cut Return Any Fields If Separator Does Not Exist

cut

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?

Best Answer

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.

Related Question