cut (Unix)
cut is a Unix command for the column-by-column extraction of text read in line by line.
Line segments can be extracted byte - ( -b
), character - ( -c
) or by field ( -f
), whereby -d
a separator can be specified. The options N
, N-M,
N-
( N
to end of line), or -M
(start of line to M
) are available for range specifications .
The first known, public version of cut was part of Unix System III in 1982 . Most Linux distributions today contain the implementation of the Gnu Core Utilities package, which was created by David M. Ihnat, David MacKenzie, and Jim Meyering.
Examples
A file a.tst contains the following lines:
foo:bar:baz:qux:quux
one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
With
% cut -c 4-10 a.tst
then, for example, the 4th – 10th Output characters in each line:
:bar:ba
:two:th
ha:beta
while
% cut -d : -f 5- a.tst
divides the lines into fields that are separated by colons and can contain different numbers of characters. From the fifth such field on, the remaining content of the line is output:
quux
five:six:seven
epsilon:zeta:eta:teta:iota:kappa:lambda:mu .
Web links
-
cut
: cut out selected fields of each line of a file - Open Group Base Specification -
cut(1)
: select portions of each line of a file - OpenBSD General Commands Manual -
cut(1)
: Remove parts of each line from files - Debian GNU / Linux Executables or Shell Commands man page -
Cut out selected fields of each line of a file Consideration of
cut
and its historical background
Individual evidence
- ↑ Markus Schnalke: Cut out selected fields of each line of a file . In: free magazine . ( marmaro.de [PDF]).
- ↑ cut (1): remove sections from each line of files - Linux man page. Retrieved March 28, 2020 .