Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Cut (Unix)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Command line utility}}{{lowercase title}} {{For|the more common operation related to copying and pasting|Cut, copy, and paste}} {{Infobox software | name = cut | logo = | screenshot = | screenshot size = | caption = | author = [[AT&T Bell Laboratories]] | developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers | released = {{Start date and age|1985|2}} | latest release version = | latest release date = | operating system = [[Unix]], [[Unix-like]], [[IBM i]] | platform = [[Cross-platform]] | genre = [[Command (computing)|Command]] | license = [[coreutils]]: [[GPLv3+]] | website = }} In [[computing]], <code>'''cut'''</code> is a [[Command-line interface|command line]] utility on [[Unix]] and [[Unix-like]] [[operating system]]s which is used to extract sections from each line of input β usually from a [[computer file|file]]. It is currently part of the [[GNU Core Utilities|GNU coreutils]] package and the [[Berkeley Software Distribution|BSD]] Base System. Extraction of line segments can typically be done by [[byte]]s (<code>-b</code>), [[character (computing)|character]]s (<code>-c</code>), or fields (<code>-f</code>) separated by a delimiter (<code>-d</code> — the [[tab character]] by default). A range must be provided in each case which consists of one of <code>N</code>, <code>N-M,</code> <code>N-</code> (<code>N</code> to the end of the line), or <code>-M</code> (beginning of the line to <code>M</code>), 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== The original [[Bell Labs]] version was written by [[Gottfried W. R. Luderer]].<ref>{{Cite web|url=https://man.openbsd.org/cut.1|title=cut(1) - OpenBSD manual pages}}</ref><ref>{{Cite web|url=https://www.tuhs.org/pipermail/tuhs/2020-January/019955.html|title=[TUHS] A portrait of cut(1)|date=15 January 2020 }}</ref> {{code|cut}} is part of the [[X/Open]] Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the [[Single Unix Specification]].<ref>{{man|cu|cut|SUS}}</ref> It first appeared in [[UNIX System III|AT&T System III UNIX]] in 1982.<ref>{{man|1|cut|FreeBSD}}</ref> The version of <code>cut</code> bundled in [[GNU]] [[coreutils]] was written by David M. Ihnat, David MacKenzie, and Jim Meyering.<ref>{{man|1|cut|ManKier}}</ref> The command is available as a separate package for [[Microsoft Windows]] as part of the [[UnxUtils]] collection of [[Native (computing)|native]] [[Windows API|Win32]] [[porting|ports]] of common GNU Unix-like utilities.<ref>{{Cite web|url=http://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}}</ref> The {{Mono|cut}} command has also been ported to the [[IBM i]] operating system.<ref>{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=[[IBM]] |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 |url-status=live|archive-url=https://web.archive.org/web/20200918130823/https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |archive-date=2020-09-18 }}</ref> ==Examples== Assuming a file named "<code>file</code>" 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: <syntaxhighlight lang="console"> $ cut -c 4-10 file :bar:ba :two:th ha:beta quick </syntaxhighlight> To output the fifth field through the end of the line of each line using the [[colon (punctuation)|colon character]] as the field delimiter: <syntaxhighlight lang="console"> $ 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 </syntaxhighlight> (note that because the [[colon (punctuation)|colon character]] is not found in the last line the entire line is shown) Option <code>-d</code> specifies a single character delimiter (in the example above it is a colon) which serves as field separator. Option <code>-f</code> which specifies range of fields included in the output (here fields range from five till the end). Option <code>-d</code> presupposes usage of option <code>-f</code>. To output the third field of each line using space as the field delimiter: <syntaxhighlight lang="console"> $ 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 </syntaxhighlight> (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: <syntaxhighlight lang="console"> $ line=process.processid $ cut -d "." -f1 <<< $line process $ cut -d "." -f2 <<< $line processid </syntaxhighlight> ==Syntax== cut [-b list] [-c list] [-f list] [-n] [-d delim] [-s] [file] Flags which may be used include: ; {{mono|-b}} : Bytes; a list following {{mono|-b}} specifies a range of [[byte]]s which will be returned, e.g. {{code|cut -b1-66}} would return the first 66 bytes of a line. NB If used in conjunction with {{mono|-n}}, no [[multi-byte]] characters will be split. NNB. {{mono|-b}} will only work on input lines of less than 1023 bytes ; {{mono|-c}} : Characters; a list following {{mono|-c}} specifies a range of characters which will be returned, e.g. {{code|cut -c1-66}} would return the first 66 characters of a line ; {{mono|-f}} : Specifies a field list, separated by a [[delimiter]] ; list : A comma separated or blank separated list of integer denoted fields, incrementally ordered. The {{mono|-}} indicator may be supplied as shorthand to allow inclusion of ranges of fields e.g. {{mono|4-6}} for ranges 4β6 or {{mono|5-}} as shorthand for field 5 to the end, etc. ; {{mono|-n}} : Used in combination with -b suppresses splits of [[multi-byte character]]s ; {{mono|-d}} : Delimiter; the character immediately following the {{mono|-d}} option is the field delimiter for use in conjunction with the {{mono|-f}} option; the default delimiter is ''tab''. Space and other characters with special meanings within the context of the [[Unix shell|shell]] in use must be enquoted or escaped as necessary. ; {{mono|-s}} : Bypasses lines which contain no field delimiters when {{mono|-f}} 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]] * [[grep]] * [[paste (Unix)]] * [[sed]] * [[awk]] ==References== {{Reflist}} ==External links== {{Wikibooks|Guide to Unix|Commands}} * {{man|cu|cut|SUS}} * [http://www.softpanorama.org/Tools/cut.shtml Softpanorama cut page]. * [http://marmaro.de/docs/freiesmagazin/cut/cut.en.pdf Cut out selected fields of each line of a file] A portrait of cut(1) and its historical background. {{Unix commands}} {{Core Utilities commands}} [[Category:Unix text processing utilities]] [[Category:Standard Unix programs]] [[Category:Unix SUS2008 utilities]] [[Category:IBM i Qshell commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Core Utilities commands
(
edit
)
Template:For
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase title
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Mono
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Unix commands
(
edit
)
Template:Wikibooks
(
edit
)