`cut -d: -f5-` prints lines even if they have no colon

by 00-Yalo   Last Updated January 14, 2018 12:02 PM

Assuming a file named "file" containing the lines:

foo:bar:baz:qux:quux
one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog

If we use the cut command with these options we get:

$ cut -d ":" -f 5- file
quux
five:six:seven
epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog

In the last line the colon character wasn't found so normally it shouldn't have taken that line because we begin with the 5th field to the end of line.

Why is that so ?

Tags : command-line


Answers 1


By default cut with the -f option prints any line that doesn't contain a delimiter character. Use -s if you don't want them:

$ cut -d ":" -f 5- -s file
quux
five:six:seven
epsilon:zeta:eta:theta:iota:kappa:lambda:mu
Florian Diesch
Florian Diesch
January 14, 2018 11:25 AM

Related Questions



Run command with spaces on startup

Updated October 19, 2017 11:02 AM



How to install ZIP file

Updated May 08, 2017 22:02 PM