cut (Unix)

cut (Unix)

In computing, cut is a Unix command line utility which is used to extract sections from each line of input — usually from a file.

Extraction of line segments can typically be done by bytes (-b), characters (-c), or fields (-f) separated by a delimiter (-d — the tab character by default). A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.

Examples

Assuming a file named file containing the 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
the quick brown fox jumps over the lazy dog

To output the fourth through tenth characters of each line:

% cut -c 4-10 file

This gives the output:

:bar:ba
:two:th
ha:beta
 quick

To output the fifth field through the end of the line of each line using the colon character as the field delimiter:

% cut -d ":" -f 5- file

This gives the output:

quux
five:six:seven
epsilon:zeta:eta:teta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog

(note that as the colon character is not found in the last line the entire line is shown)

Option -d specified a single character delimiter (in the example above it is a blank) which serves as field separator. option -f which specifies range of fields included in the output (here fields range from five till the end ). Option -d presuppose usage of option -f.

To output the third field of each line using space as the field delimiter:

%cut -d " " -f 3 file

This gives the output:

foo:bar:baz:qux:quux
one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
brown

(note that as the space character is not found in the first three lines these entire lines are shown)


See also

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Cut (Unix) — Voir « cut » sur le Wiktionnaire …   Wikipédia en Français

  • cut (Unix) — Sur les autres projets Wikimedia : « Cut (Unix) », sur le Wiktionnaire (dictionnaire universel) cut est une commande POSIX qui retire des passages de chaque ligne des fichiers passés en paramètre et affiche le résultat sur la… …   Wikipédia en Français

  • Cut (Unix) — cut ist ein Unix Kommando zur spaltenweisen Manipulation von zeilenweise eingelesenem Text. Zeilensegmente können byte ( b), zeichen ( c) oder felderweise ( f) extrahiert werden, wobei mittels d ein Trennzeichen spezifiziert werden kann. Für… …   Deutsch Wikipedia

  • cut (Unix) — cut ist ein Unix Kommando zur spaltenweisen Extraktion von zeilenweise eingelesenem Text. Zeilensegmente können byte ( b), zeichen ( c) oder felderweise ( f) extrahiert werden, wobei mittels d ein Trennzeichen spezifiziert werden kann. Für… …   Deutsch Wikipedia

  • Cut (Unix) — In computing, cut is a Unix command line utility which is used to extract sections from each line of input usually from a file.Extraction of line segments can typically be done by bytes ( b), characters ( c), or fields ( f) separated by a… …   Wikipedia

  • Cut (commande UNIX) — cut (Unix) Voir « cut » sur le Wiktionnaire …   Wikipédia en Français

  • UNIX-Kommandos — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

  • Unix-Befehle — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

  • Unix-Kommando — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

  • Unix Kommandos — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”