0
0
Linux CLIscripting~5 mins

cut (extract columns) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the cut command do in Linux?
The cut command extracts sections from each line of input, usually columns or fields, based on delimiters or character positions.
Click to reveal answer
beginner
How do you extract the first 5 characters of each line using cut?
Use cut -c 1-5 filename to get characters 1 through 5 from each line of the file.
Click to reveal answer
beginner
What option do you use with cut to specify a delimiter other than the default tab?
Use -d followed by the delimiter character, for example cut -d ',' -f 2 file.csv to extract the second field separated by commas.
Click to reveal answer
beginner
How do you extract the 2nd and 4th fields from a comma-separated file using cut?
Use cut -d ',' -f 2,4 filename to get the 2nd and 4th fields separated by commas.
Click to reveal answer
beginner
What happens if you use cut -f 1-3 without specifying a delimiter?
By default, cut uses the tab character as the delimiter. So it extracts fields 1 to 3 separated by tabs.
Click to reveal answer
Which cut option extracts characters by position?
A-d
B-f
C-c
D-s
How do you specify a comma as the delimiter in cut?
A-d ,
B-c ,
C-f ,
D-s ,
What does cut -f 2-4 do by default?
AExtracts characters 2 to 4
BExtracts fields 2 to 4 separated by tabs
CExtracts fields 2 to 4 separated by commas
DExtracts lines 2 to 4
Which command extracts the first 3 characters of each line?
Acut -s 1-3
Bcut -f 1-3
Ccut -d 1-3
Dcut -c 1-3
What does the -s option do in cut?
ASuppress lines without delimiter
BSelect specific fields
CSpecify delimiter
DExtract characters
Explain how to use cut to extract specific fields from a comma-separated file.
Think about how to tell cut what separates the fields and which fields to get.
You got /5 concepts.
    Describe the difference between extracting characters and extracting fields with cut.
    Consider what you want to cut: fixed positions or separated parts.
    You got /4 concepts.