cut Linux Command Cheatsheet




cut Linux Command is used to extract sections from each line of input or from a file. Extraction of line segments can be done by bytes (-b), characters (-c), fields (-f) or by delimiter (-d) tab character is the default delimiter.

Segment types

segmentdescription
-bbytes
-ccharacters
-ffields
-ddelimiter. Note: tab is the default delimiter

Range specification

Rangedescription
NNth
N-MN to M
N-N to end of line
-Mbeginning to M

Note: N, M counted from 1, not 0.

Examples

Lets say we have a file foo.txt with following content

abc-def-ghi-jkl
mno-pqr-stu-vwx
123-456-7890
$ cut -c 5-7 foo.txt 
def
pqr
456
$ cut -d "-" -f 1-2 foo.txt 
abc-def
mno-pqr
123-456
$ cut -c 5- foo.txt
def-ghi-jkl
pqr-stu-vwx
456-7890


┬ęCopyright 2020 OneCompiler | Privacy Policy | Terms & Conditions