Cut (Unix)

cut
Original author(s)AT&T Bell Laboratories
Developer(s)Various open-source and commercial developers
Initial releaseFebruary 1985; 39 years ago (1985-02)
Operating systemUnix, Unix-like, IBM i
PlatformCross-platform
TypeCommand
Licensecoreutils: GPLv3+

In computing, cut is a command line utility on Unix and Unix-like operating systems 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 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.

History

The original Bell Labs version was written by Gottfried W. R. Luderer.[1][2] 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.[3] It first appeared in AT&T System III UNIX in 1982.[4]

The version of cut bundled in GNU coreutils was written by David M. Ihnat, David MacKenzie, and Jim Meyering.[5] The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[6] The cut command has also been ported to the IBM i operating system.[7]

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 specifies 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] [-c list] [-f list] [-n] [-d delim] [-s] [file]

Flags which may be used include:

-b
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
-c
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
-f
Specifies a field list, separated by a delimiter
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. 4-6 for ranges 4–6 or 5- as shorthand for field 5 to the end, etc.
-n
Used in combination with -b suppresses splits of multi-byte characters
-d
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.
-s
Bypasses lines which contain no field delimiters when -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

References

  1. ^ "cut(1) - OpenBSD manual pages".
  2. ^ "[TUHS] A portrait of cut(1)". 15 January 2020.
  3. ^ cut – Shell and Utilities Reference, The Single UNIX Specification, Version 4 from The Open Group
  4. ^ cut(1) – FreeBSD General Commands Manual
  5. ^ cut(1) – Linux General Commands Manual
  6. ^ "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
  7. ^ IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Archived (PDF) from the original on 2020-09-18. Retrieved 2020-09-05.

Read other articles:

Questa voce sull'argomento elementi architettonici è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Esempio di volte a ventaglio nella cattedrale di Winchester. Colonna a ventaglio della scalinata che porta all'Aula Magna presso la Christ Church di Oxford. La volta a ventaglio è una forma di volta utilizzata nel gotico inglese. È caratterizzata dal fatto che le coste sono tutte della stessa curvatura e sono spaziate in maniera equidistante, in modo da ri…

Todd HaberkornHaberkorn pada tahun 2015LahirTodd Michael Haberkorn16 Agustus 1982 (umur 41)Arlington, Texas, Amerika SerikatTempat tinggalLos Angeles, California, Amerika Serikat[1][2]Nama lainTodd StoneAlmamaterSouthern Methodist University (BFA)PekerjaanPengisi suara, ADR voice directorTahun aktif1994 - sekarangAgenThe Horne AgencyVOX Inc.Anak1[1][3]Situs webwww.thehabertat.com Todd Michael Haberkorn (lahir 16 Agustus 1982 di Arlington, Texas, Ame…

Exceptionally precocious child Wunderkind redirects here. For other uses, see Wunderkind (disambiguation). Wonder child redirects here. For the song by Christian Walz, see Wonderchild. Boy genius redirects here. For other uses, see Boy genius (disambiguation). Whiz kid redirects here. For other uses, see Whiz Kids. Wolfgang Amadeus Mozart, a well-known child prodigy, started composing at the age of five. A child prodigy is a person under the age of ten who produces meaningful work in some domain…

Letter written for a didactic purpose This article is about the literary genre of letter-writing. For other uses, see Epistulae (disambiguation). For the Manichaean text, see The Epistles (Manichaeism). Saint Paul Writing His Epistles, by Valentin de Boulogne or Nicolas Tournier (c. 16th century, Blaffer Foundation Collection, Houston, TX). An epistle (/ɪˈpɪsəl/; from Ancient Greek ἐπιστολή (epistolḗ) 'letter') is a writing directed or sent to a person or group of pe…

Burmese army general Lieutenant GeneralKyaw Swar Linကျော်စွာလင်းQuartermaster General of Myanmar ArmyIncumbentAssumed office May 2020Preceded byLieutenant General Nyo Saw Personal detailsBorn1971 (age 52–53)NationalityBurmeseSpouseNan Ku KuAlma materDefence Services AcademyMilitary serviceAllegiance MyanmarBranch/service Myanmar ArmyRank Lieutenant General Kyaw Swar Lin (Burmese: ကျော်စွာလင်း) is a Burmese military general …

This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Moto G9 – news · newspapers · books · scholar · JSTOR (November 2020) (Learn how and when to remove this messa…

Tendency of matter to change volume in response to a change in temperature This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Thermal expansion – news · newspapers · books · scholar · JSTOR (September 2017) (Learn how and when to remove this message) Expansion joint in a road bridge used to avoid damage from therm…

Kandungan nutrisi masing-masing komponen dari gandum utuh Serealia utuh adalah serealia yang terdiri dari inti serealia, endosperma, dan bekatul. Berkebalikan dengan serealia giling (refined grain) yang hanya mengandung endospermanya. Pada awalnya, serealia yang dimakan manusia disajikan atau diolah secara utuh, tetapi kebutuhan terhadap usia simpan serealia membuat hasil pertanian ini diproses sehingga hanya menyisakan endospermanya saja. Bekatul dan inti serealia mengandung lemak dan protein y…

US Army combat formation Big Red One redirects here. For the motion picture, see The Big Red One. For the video game, see Call of Duty 2: Big Red One. For other uses, see 1st Division. 1st Infantry DivisionInsignia of the 1st Infantry DivisionActive24 May 1917 - presentCountryUnited StatesBranchUnited States ArmyTypeCombined armsSizeDivisionPart ofIII Armored CorpsGarrison/HQFort Riley, KansasNickname(s)The Big Red One[1] (abbreviated BRO[2]) The Bloody FirstMotto(s)No Missi…

Major GeneralTahir Jalil Habbush al-Tikritiطاهر جليل حبوشHabbush as a Major General in 1989Director of the Iraqi Intelligence ServiceIn office1995–2003Preceded bySabawi Ibrahim al-TikritiSucceeded byOffice abolishedDirector of the Directorate of General SecurityIn office1997–1999Preceded byTaha Abbas al-AhbabiSucceeded byRafi Abdul Latif Tulfah Personal detailsBorn (1950-01-01) January 1, 1950 (age 74)IraqOccupationPolice officer Intelligence officerAwardsMother of All Battl…

دايانارا توريس (بالإسبانية: Dayanara Torres Delgado)‏  توريس في أبريل 2011 معلومات شخصية الاسم عند الميلاد دايانارا توريس ديلغادو الميلاد 28 أكتوبر 1974 (العمر 49 سنة)سان خوان (بورتوريكو) الجنسية الولايات المتحدة  اللغات المحكية الإسبانية،  والتاغالوغية  الطول 5 قدم 8.5 بوصة (1.7…

Angkatan Darat PrancisArmée de TerreDibentuk1445NegaraPrancisTipe unitTentaraJumlah personel114,850 personel aktif ditambah 22,750 personel cadangan[1]Bagian dariAngkatan Bersenjata PrancisJulukanLa grande muetteSi bisu yang hebatMotoHonneur et PatrieKehormatan dan Tanah AirColors on logo:Merah, Putih, dan BiruPertempuran Daftar konflik Perang Seratus Tahun (1337–1453) Perang Kolonial (1534–1980) Peperangan Italia Perang Tiga Puluh Tahun Perang Sembilan Tahun Perang Penerus Spanyol …

Administrative district of New France (1682–1803) Colony of LouisianaLouisiane (French)District of New France1682–17621801–1803 Flag[a] The lesser coat of arms of France as used by the Government New France before the Treaty of UtrechtCapitalMobile (1702–1720)Biloxi (1720–1722)La Nouvelle-Orléans (after 1722)Population •  1,702 – 1,500 Europeans (east and west of the Mississippi)•  1,763 – 20,000 Europeans and Africans (west and east of the Mis…

American Buddhist writer and academic For the baseball player, see Bob Thurman. For the novelist, see Rob Thurman. Robert ThurmanThurman in 2014BornRobert Alexander Farrar Thurman (1941-08-03) August 3, 1941 (age 82)New York City, U.S.Other namesBob Thurman, Alexander Thurman, Alecsander ThermenAlma materHarvard University (BA, MA, PhD)Spouses Marie-Christophe de Menil ​ ​(m. 1960; div. 1961)​ Nena von Schlebrügge ​ ​…

High school debating championship Kathmandu Debates General InformationStarted2013 by Sano Sansar InitiativeWebsitewww.sanosansar.org/ktmdebatesKey PeopleSagar Aryal, Initiator Pradeep Ghimire, Tournament DirectorFocusKarl Popper Debating ChampionshipFacebookKathamandu-Debates-Official-Sitevte The Kathmandu Debates is a high school debating championship led by the youth of the Sano Sansar Initiative. The program aims to provide a platform to encourage young people to engage in social, political,…

Hindu epic poem by Bhāravi KirātārjunīyaArjuna receives the Pashupatastra from Shiva. Painting by Raja Ravi Varma, 19th century.InformationReligionHinduismAuthorBhāraviLanguageSanskritPeriodPallava Kirātārjunīya (Sanskrit: किरातार्जुनीय, Of Arjuna and the kirata) is an epic poem by Bhāravi, written in Sanskrit.[1] Believed to have been composed in the 6th century or earlier, it consists of eighteen cantos describing the combat between Arjuna and Shiva (…

NaskahUncial 027Fragmen memuat teks Lukas 9:23Fragmen memuat teks Lukas 9:23NamaNitriensisTandaRTeksInjil Lukas †Waktu~550 MAksarabahasa YunaniDitemukan1842Kini diBritish Library, Add. 17211Ukuran29,5 cm kali 23,5 cmJenisTeks BizantinKategoriV Codex Nitriensis diberi kode R atau 027 (dalam penomoran Gregory-Aland), ε 22 (dalam penomoran von Soden), adalah sebuah naskah uncial kuno berisi bagian Perjanjian Baru dari Alkitab Kristen dalam bahasa Yunani Koine. Memuat Kitab-kitab I…

NGC 5374   الكوكبة العذراء[1]  رمز الفهرس NGC 5374 (الفهرس العام الجديد)2MASX J13572962+0605487 (Two Micron All-Sky Survey, Extended source catalogue)IRAS F13549+0620 (IRAS)MCG+01-36-004 (فهرس المجرات الموروفولوجي)UGC 8874 (فهرس أوبسالا العام)IRAS 13549+0620 (IRAS)PGC 49650 (فهرس المجرات الرئيسية)Z 1355.0+0621 (فهرس المجرات وعناقيد المجرات)Z 46-16 (فهرس…

Karl-Heinz Rummenigge Informasi pribadiTanggal lahir 25 September 1955 (umur 68)Tempat lahir Lippstadt, Jerman BaratTinggi 1,82 m (5 ft 11+1⁄2 in)Posisi bermain Forward, Attacking MidfielderKarier junior1963–1974 Borussia LippstadtKarier senior*Tahun Tim Tampil (Gol) 1974–19841984–19871987–1989 Bayern MunichInter MilanServette FC 310 (162)064 0(24)050 0(34) Tim nasional1976–1986 Jerman Barat 095 0(45) * Penampilan dan gol di klub senior hanya dihitung dari lig…

American poker player (1944–2019) Ron RoseRose in the 2006 World Series of Poker.ResidenceDayton, Ohio, U.S.BornRonald Morris RoseSeptember 4, 1944Vancouver, Washington, U.S.DiedOctober 24, 2019 (aged 75)Cincinnati, Ohio, U.S.World Series of PokerBracelet(s)1Final table(s)2Money finish(es)4Highest ITMMain Event finishNoneWorld Poker TourTitle(s)1 (+1)Final table(s)2 (+1)Money finish(es)2 (+1) Ronald Morris Rose (September 4, 1944 – October 24, 2019) was an American poker player from Dayton, …