Cut is a Unix command-line tool used to extract fields and the like from lines of input, available on many platforms.
-clist: Display selected characters of lines.
-flist: Display selected fields of lines, separated by tab by default.
-dchar: Switch field separator from tab to char.
-s: Do not display ("suppress") lines that contain no occurence of the field separator.
-b: Display selected bytes of lines.
-n: Do not split multi-byte characters.
Displays the 1st field of each line, using tab as the field separator.
Displays the 2nd field of each line, using colon as the field separator.
Outputs "a b c", disregarding the reversed order after -f.
Outputs the 2nd and every later field, so "b c d".
Instead of fields, treats characters. Thus, outputs "cd".
Displays "b", separating fields by any number of tabs or spaces. Thus, for awk, "b" is the 2nd field, while for cut -d" ", "b" is the 3rd field.
Displays "ba", preserving the order of the fields as specified.
echo a b|sed "s/ */ /g" |cut -f2 -d" "
Displays "b". Uses sed to first compact a sequence of spaces into a single space.
There is no way to specify "one or more spaces" or the like as the field delimiter.
There is no way to change the order of the fields on the output.
A version of GNU cut for MS Windows is available from GnuWin32 project, as well as from Cygwin.
This page was last edited on 11 July 2018, at 15:38.