0
0
Bash Scriptingscripting~5 mins

cut and paste in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the cut command do in bash scripting?
The cut command extracts sections from each line of input, usually by specifying a delimiter and fields or by character positions.
Click to reveal answer
beginner
How do you use paste in bash scripting?
The paste command merges lines of files horizontally, joining corresponding lines from each file separated by a tab or a specified delimiter.
Click to reveal answer
beginner
Example: What does cut -d',' -f2 file.txt do?
It extracts the second field from each line of file.txt, assuming fields are separated by commas.
Click to reveal answer
intermediate
How can you combine cut and paste to rearrange columns?
You can use cut to extract columns from files and then use paste to join those columns side by side in a new order.
Click to reveal answer
beginner
What option in cut lets you select characters instead of fields?
The -c option lets you select specific character positions from each line.
Click to reveal answer
Which cut option extracts fields based on a delimiter?
A-d
B-c
C-s
D-f
What does the paste command do?
AJoins lines from multiple files horizontally
BSorts lines alphabetically
CDeletes lines from a file
DExtracts columns from a file
How do you extract the first 5 characters of each line using cut?
Acut -f1-5
Bcut -c1-5
Ccut -d1-5
Dcut -s1-5
Which command sequence joins the second column of file1.txt with the first column of file2.txt?
Apaste file1.txt file2.txt
Bcut -f2 file1.txt | paste -f1 file2.txt
Ccut -f2 file1.txt | paste - <(cut -f1 file2.txt)
Dcut -f2 file1.txt | paste - file2.txt
What delimiter does paste use by default?
ATab
BComma
CSpace
DColon
Explain how you would extract specific columns from a CSV file and then combine them in a new order using bash commands.
Think about using cut with -d and -f, then paste to join columns side by side.
You got /5 concepts.
    Describe the difference between selecting fields and selecting characters with the cut command.
    Fields depend on delimiters; characters are positions in the line.
    You got /5 concepts.