cut (Unix)

from Wikipedia, the free encyclopedia

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 -da separator can be specified. The options N, N-M, N-( Nto 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

Individual evidence

  1. Markus Schnalke: Cut out selected fields of each line of a file . In: free magazine . ( marmaro.de [PDF]).
  2. cut (1): remove sections from each line of files - Linux man page. Retrieved March 28, 2020 .