Low Orbit Flux Logo 2 F

Linux Command - cut

The linux command cut is used to split apart lines in a file.

It is more simple and less functional than awk. It works great for splitting things apart.

Chose only one of either list type: -b, -c, -f

-b specify bytes list
-c specify char list
-f specify field list ( delimited by tabs by default )
-d specify delimiter
-s only delimited
–complement Opposite of what was selected
–output-delimiter Customized output delimiter string

First column of a csv file:



cut -d ',' -f 1 test.txt

First column of piped output:



ps -ef | cut -d ' ' -f 1

Display bytes 1, 2, 3:



cut -b 1,2,3   test.txt

Display characters 1, 2, 3:



cut -c 1,2,3   test.txt

Display fields 1, 2, 3:



cut -f 1,2,3   test.txt

Field 5 to 9:



cut -f 5-9   test.txt

Field 5 to end:



cut -f 5-   test.txt

Beginning to filed 8:



cut -f -8   test.txt

Use a space as a delimiter:



cut -d ' ' -f 2,3 test.txt

Use a colon as a delimiter:



cut -d ':' -f 2,3 test.txt

Use a commas a delimiter ( great for csv files ):



cut -d ',' -f 2,3 test.csv

Only show delimited lines:



cut -s -d ' ' -f 2,3 test.txt

Opposite of what was selected:



cut -d ' ' -f 2,3 --complement test.txt

Use a custom output delimiter:



cut -d ' ' -f 2,3 --output-delimiter="|===|" test.txt