cut
![]() |
![]() |
![]() |
![]() |
cut
Cut out selected fields of each line of a file (POSIX)
Syntax:
cut -c list [file...] cut -f list [-d delim] [-s] [file...]
Runs on:
Neutrino
Options:
- -c list
- Cut out the characters found in the character positions specified by list. For example, a list of -c 1-64 outputs the first 64 characters of each line.
- -d delim
- Use the delimiter specified by delim (default is tab).
- -f list
- Cut out the fields specified by list. For example, -f 2,9 outputs the second and ninth fields. The fields described by list are assumed to be separated in the file by a delimiter character (see option -d). Lines without field delimiters are passed through intact, unless -s is specified.
- -s
- If -f is specified, suppress lines with no field delimiters.
- file
- The pathname of a text file, whose contents are used instead of the standard input.
Description:
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.
Examples:
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
Exit status:
- 0
- All input files were output successfully.
- >0
- An error occurred.
See also:
![]() |
![]() |
![]() |
![]() |

![[Previous]](../prev.gif)
![[Contents]](../contents.gif)
![[Index]](../keyword_index.gif)
![[Next]](../next.gif)
