Cutting a file column-wise with cut
The cut command splits a file by column instead of lines. This is useful for processing files with fixed-width fields, Comma Separated Values (CSV files), or space delimited files such as the standard log files.
How to do it...
The cut command extracts data between character locations or columns. You can specify the delimiter that separates each column. In the cut terminology, each column is known as a field.
- The -f option defines the fields to extract:
cut -f FIELD_LIST filenameFIELD_LIST is a list of columns that are to be displayed. The list consists of column numbers delimited by commas. Consider this example:
$ cut -f 2,3 filenameHere, the second and the third columns are displayed.
- The
cutcommand also reads input fromstdin.
Tab is the default delimiter for fields. Lines without delimiters will be printed. The -s option will disable printing lines without delimiter characters. The following commands demonstrate extracting columns from a tab delimited file...