Tutorial by Examples

The typical usage is with CSV-type files, where each line consists of fields separated by a delimiter, specified by the option -d. The default delimiter is the TAB character. Suppose you have a data file data.txt with lines like 0 0 755 1482941948.8024 102 33 4755 1240562224.3205 1003 1 644 12199...
You cannot have more than one delimiter: if you specify something like -d ",;:", some implementations will use only the first character as a delimiter (in this case, the comma.) Other implementations (e.g. GNU cut) will give you an error message. $ cut -d ",;:" -f2 <<<&...
$ cut -d, -f1,3 <<<"a,,b,c,d,e" a,b is rather obvious, but with space-delimited strings it might be less obvious to some $ cut -d ' ' -f1,3 <<<"a b c d e" a b cut cannot be used to parse arguments as the shell and other programs do.
There is no way to protect the delimiter. Spreadsheets and similar CSV-handling software usually can recognize a text-quoting character which makes it possible to define strings containing a delimiter. With cut you cannot. $ cut -d, -f3 <<<'John,Smith,"1, Main Street"' "1 ...
You can only extract portions of lines, not reorder or repeat fields. $ cut -d, -f2,1 <<<'John,Smith,USA' ## Just like -f1,2 John,Smith $ cut -d, -f2,2 <<<'John,Smith,USA' ## Just like -f2 Smith

Page 1 of 1