World Library  
Flag as Inappropriate
Email this Article

Cut (Unix)

Article Id: WHEBN0000821605
Reproduction Date:

Title: Cut (Unix)  
Author: World Heritage Encyclopedia
Language: English
Subject: Comm, UnxUtils, Cut, Standard Unix programs, Toybox
Collection: Standard Unix Programs, Unix Sus2008 Utilities, Unix Text Processing Utilities
Publisher: World Heritage Encyclopedia

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. It is currently part of the GNU coreutils package and the BSD Base System. It first appeared in AT&T System III UNIX in 1982.[1]

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 1
  • Syntax 2
  • See also 3
  • References 4
  • External links 5


Assuming a file named "file" containing the lines:

the quick brown fox jumps over the lazy dog

To output the fourth through tenth characters of each line:

$ cut -c 4-10 file

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
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

(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
$ cut -d "." -f2 $line


 cut [-b] [-c] [-f list] [-n] [-d delim] [-s] [file]

Flags which may be used include

Bytes; a list following -b specifies a range of bytes which will be returned, e.g. cut -b1-66 would return the first 66 bytes of a line. NB If used in conjunction with -n, no multi-byte characters will be split. NNB. -b will only work on input lines of less than 1023 bytes
Characters; a list following -c specifies a range of characters which will be returned, e.g. cut -c1-66 would return the first 66 characters of a line
Specifies a field list, separated by a delimiter
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. 4-6 for ranges 4–6 or 5- as shorthand for field 5 to the end, etc.
Used in combination with -b suppresses splits of multi-byte characters
Delimiter; the character immediately following the -d option is the field delimiter for use in conjunction with the -f 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 -f is specified, unless otherwise indicated.
The file (and accompanying path if necessary) to process as input. If no file is specified then standard input will be used.

See also


  1. ^

External links

This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.