Challenge - 5 Problems
Cut and Paste Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of cut command with delimiter and field
What is the output of this command when run on the file
Command:
data.txt containing:apple,banana,cherry dog,elephant,fox
Command:
cut -d',' -f2 data.txt
Bash Scripting
cut -d',' -f2 data.txtAttempts:
2 left
💡 Hint
The
-d option sets the delimiter, and -f selects the field number.✗ Incorrect
The command cuts the second field separated by commas, so it outputs 'banana' and 'elephant' each on a new line.
💻 Command Output
intermediate2:00remaining
Paste command combining two files
Given two files:
What is the output of:
file1.txt: 1 2 3 file2.txt: a b c
What is the output of:
paste file1.txt file2.txt
Bash Scripting
paste file1.txt file2.txt
Attempts:
2 left
💡 Hint
Paste joins lines from files side by side separated by tabs by default.
✗ Incorrect
Paste combines lines from both files separated by a tab character, so each line from file1.txt is joined with the corresponding line from file2.txt.
📝 Syntax
advanced2:00remaining
Correct cut command to extract characters
Which option correctly extracts characters 3 to 5 from each line of
input.txt?Attempts:
2 left
💡 Hint
Use
-c to select character positions.✗ Incorrect
Option B uses
-c3-5 to select characters from position 3 to 5. Option B uses fields which is incorrect here. Option B uses an invalid delimiter. Option B selects characters 3 and 5 only, not the range.💻 Command Output
advanced2:00remaining
Output of paste with custom delimiter
Given two files:
What is the output of:
names.txt: John Jane ages.txt: 30 25
What is the output of:
paste -d ':' names.txt ages.txt
Bash Scripting
paste -d ':' names.txt ages.txtAttempts:
2 left
💡 Hint
The
-d option sets the delimiter between pasted columns.✗ Incorrect
Paste joins lines from both files with ':' as delimiter, so each name is joined with the corresponding age separated by a colon.
🚀 Application
expert3:00remaining
Combine cut and paste to swap columns
You have a file
Which command sequence swaps the two columns so output is:
data.csv with comma-separated values:red,apple blue,berry green,grape
Which command sequence swaps the two columns so output is:
apple,red berry,blue grape,green
Attempts:
2 left
💡 Hint
Use process substitution to cut columns and paste them in swapped order.
✗ Incorrect
Option A correctly cuts the second column first, then the first column, and pastes them with comma delimiter, swapping columns. Option A pipes first cut but incorrectly uses paste with pipe and process substitution causing mismatch. Option A uses temp files but is correct in output; however, it is less elegant and not a single command sequence. Option A pastes original order, not swapped.