2025-03-14 21:59:59 -06:00
|
|
|
# cut
|
|
|
|
|
|
|
|
|
|
> Cut out fields from `stdin` or files.
|
|
|
|
|
> More information: <https://www.gnu.org/software/coreutils/manual/html_node/cut-invocation.html>.
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
- Print the fifth character on each line:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`{{command}} | cut {{[-c|--characters]}} 5`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
- Print the fifth to tenth character of each line of the specified file:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`cut {{[-c|--characters]}} 5-10 {{path/to/file}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
- Split each line in a file by a delimiter into fields and print fields two and six (default delimiter is `TAB`):
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`cut {{[-f|--fields]}} 2,6 {{path/to/file}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
- Split each line by the specified delimiter and print all from the second field onward:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`{{command}} | cut {{[-d|--delimiter]}} "{{delimiter}}" {{[-f|--fields]}} 2-`
|
|
|
|
|
|
|
|
|
|
- Use space as a delimiter and print only the first 3 fields:
|
|
|
|
|
|
|
|
|
|
`{{command}} | cut {{[-d|--delimiter]}} " " {{[-f|--fields]}} -3`
|
|
|
|
|
|
|
|
|
|
- Print specific fields of lines that use `NUL` to terminate lines instead of newlines:
|
|
|
|
|
|
|
|
|
|
`{{find . -print0}} | cut {{[-z|--zero-terminated]}} {{[-d|--delimiter]}} "{{/}}" {{[-f|--fields]}} {{2}}`
|