Cut out selected fields of each line of a file (POSIX)
cut -c list [file...] cut -f list [-d delim] [-s] [file...]
For every file you name, the cut utility cuts out columns or fields from each line, concatenates them, and writes them to the standard output.
If the fields are of a fixed length, you can select them by character position with option -c. If, however, the fields vary in length from line to line, you can select them with the -f option, provided they're separated by a delimiter character. By default, cut assumes the field delimiter character to be tab. You can use the -d option to specify another delimiter.
In options -c and -f, list is a comma-separated list of integers (in increasing order), with an optional dash (-) to indicate ranges.
You can use the cut utility as a filter; if no files are given, the standard input is used.
The following are examples of the list argument:
list argument: | Meaning: |
---|---|
1,4,7 | Select the first, fourth, and seventh characters or fields. |
1-3,8 | Equivalent to 1, 2, 3, 8. |
-5,10 | Equivalent to 1, 2, 3, 4, 5, 10. |
3- | Equivalent to the third through last. |
Map userids to names:
cut -d: -f1,5 /etc/passwd
List filenames and their permissions:
ls -l | cut -c57-79,56,56,1-11