HOME

TheInfoList



OR:

In
computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes, and development of both hardware and software. Computing has scientific, ...
, cut is a
command line A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
utility on
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
and
Unix-like A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
s which is used to extract sections from each line of input — usually from a file. It is currently part of the GNU coreutils package and the BSD Base System. Extraction of line segments can typically be done by
byte The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable unit ...
s (-b),
character Character or Characters may refer to: Arts, entertainment, and media Literature * ''Character'' (novel), a 1936 Dutch novel by Ferdinand Bordewijk * ''Characters'' (Theophrastus), a classical Greek set of character sketches attributed to The ...
s (-c), or fields (-f) separated by a delimiter (-d — the
tab character The tab key (abbreviation of tabulator key or tabular key) on a keyboard is used to advance the cursor to the next tab stop. History The word ''tab'' derives from the word ''tabulate'', which means "to arrange data in a tabular, or table, f ...
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.


History

is part of the
X/Open X/Open group (also known as the Open Group for Unix Systems and incorporated in 1987 as X/Open Company, Ltd.) was a consortium founded by several European UNIX systems manufacturers in 1984 to identify and promote open standards in the field of in ...
Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification. It first appeared in AT&T System III UNIX in 1982. The version of cut bundled in
GNU GNU () is an extensive collection of free software Free software or libre software is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any ...
coreutils The GNU Core Utilities or coreutils is a package of GNU software containing implementations for many of the basic tools, such as cat, ls, and rm, which are used on Unix-like operating systems. In September 2002, the ''GNU coreutils'' were c ...
was written by David M. Ihnat, David MacKenzie, and Jim Meyering. The command is available as a separate package for Microsoft Windows as part of the
UnxUtils UnxUtils is a collection of ports of common GNU Unix-like utilities to native Win32, with executables only depending on the Microsoft C- runtime msvcrt.dll. The collection was last updated externally on April 15, 2003, by Karl M. Syring. ...
collection of native
Win32 The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. The name Windows API collectively refers to several different platform implementations ...
ports of common GNU Unix-like utilities. The command has also been ported to the
IBM i IBM i (the ''i'' standing for ''integrated'') is an operating system developed by IBM for IBM Power Systems. It was originally released in 1988 as OS/400, as the sole operating system of the IBM AS/400 line of systems. It was renamed to i5/OS i ...
operating system.


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:theta: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 :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 quux five:six:seven epsilon:zeta:eta:theta:iota:kappa:lambda:mu the quick brown fox jumps over the lazy dog (note that because 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 colon) 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 presupposes usage of option -f. To output the third field of each line using space as the field delimiter: $ cut -d " " -f 3 file foo:bar:baz:qux:quux one:two:three:four:five:six:seven alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu brown (Note that because the space character is not found in the first three lines these entire lines are shown.) To separate two words having any delimiter: $ line=process.processid $ cut -d "." -f1 <<< $line process $ cut -d "." -f2 <<< $line processid


Syntax

cut
b list B, or b, is the second Letter (alphabet), letter of the Latin-script alphabet, used in the English alphabet, modern English alphabet, the alphabets of other western European languages and others worldwide. Its name in English is ''English ...
c list f list n d delim s
ile Ile may refer to: * iLe, a Puerto Rican singer * Ile District (disambiguation), multiple places * Ilé-Ifẹ̀, an ancient Yoruba city in south-western Nigeria * Interlingue (ISO 639:ile), a planned language * Isoleucine, an amino acid * Another ...
Flags which may be used include: ; : Bytes; a list following specifies a range of
byte The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable unit ...
s which will be returned, e.g. would return the first 66 bytes of a line. NB If used in conjunction with , no multi-byte characters will be split. NNB. will only work on input lines of less than 1023 bytes ; : Characters; a list following specifies a range of characters which will be returned, e.g. would return the first 66 characters of a line ; : Specifies a field list, separated by a
delimiter A delimiter is a sequence of one or more characters for specifying the boundary between separate, independent regions in plain text, mathematical expressions or other data streams. An example of a delimiter is the comma character, which acts as ...
; list : A comma separated or blank separated list of integer denoted fields, incrementally ordered. The indicator may be supplied as shorthand to allow inclusion of ranges of fields e.g. for ranges 4–6 or as shorthand for field 5 to the end, etc. ; : Used in combination with -b suppresses splits of
multi-byte character A variable-width encoding is a type of character encoding scheme in which codes of differing lengths are used to encode a character set (a repertoire of symbols) for representation, usually in a computer. Most common variable-width encodings are ...
s ; : Delimiter; the character immediately following the option is the field delimiter for use in conjunction with the option; the default delimiter is ''tab''. Space and other characters with special meanings within the context of the shell in use must be enquoted or escaped as necessary. ; : Bypasses lines which contain no field delimiters when is specified, unless otherwise indicated. ; file : The file (and accompanying path if necessary) to process as input. If no file is specified then standard input will be used.


See also

*
List of Unix commands This is a list of Unix commands as specified by IEEE Std 1003.1-2008, which is part of the Single UNIX Specification (SUS). These commands can be found on Unix operating systems and most Unix-like operating systems. List See also * List of G ...
*
grep grep is a command-line utility for searching plain-text data sets for lines that match a regular expression. Its name comes from the ed command ''g/re/p'' (''globally search for a regular expression and print matching lines''), which has the sa ...
* paste (Unix) * sed * awk


References


External links

*
Softpanorama cut page

Cut out selected fields of each line of a file
A portrait of cut(1) and its historical background. {{Core Utilities commands Unix text processing utilities Standard Unix programs Unix SUS2008 utilities IBM i Qshell commands