Challenge - 5 Problems
Sed Stream Editor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this sed command?
Given a file
What is the output of:
data.txt with content:apple banana cherry banana apple
What is the output of:
sed 's/banana/orange/' data.txt
Linux CLI
sed 's/banana/orange/' data.txtAttempts:
2 left
💡 Hint
Remember, sed replaces only the first match per line by default.
✗ Incorrect
The command replaces the first occurrence of 'banana' with 'orange' on each line. Only the second line has 'banana' as the first occurrence, so only that line changes.
💻 Command Output
intermediate2:00remaining
What does this sed command output?
Given
What is the output of:
file.txt content:cat bat rat mat
What is the output of:
sed -n '/at/p' file.txt
Linux CLI
sed -n '/at/p' file.txtAttempts:
2 left
💡 Hint
The -n option suppresses automatic printing; /pattern/p prints matching lines.
✗ Incorrect
The command prints only lines matching 'at'. All lines contain 'at', so all lines print exactly as in the file.
📝 Syntax
advanced2:00remaining
Which sed command correctly deletes lines 2 to 4?
You want to delete lines 2, 3, and 4 from a file using sed. Which command is correct?
Attempts:
2 left
💡 Hint
Ranges in sed use a comma, not a dash or semicolon.
✗ Incorrect
The correct syntax for a range is 'start,end' followed by the command. '2,4d' deletes lines 2 through 4.
🔧 Debug
advanced2:00remaining
Why does this sed command fail?
You run:
but it outputs the original text unchanged. Why?
sed 's/\(foo\)\(bar\)/\2\1/' file.txt
but it outputs the original text unchanged. Why?
Linux CLI
sed 's/\(foo\)\(bar\)/\2\1/' file.txtAttempts:
2 left
💡 Hint
Check if the input file contains the pattern 'foobar'.
✗ Incorrect
The command syntax is correct. If the file does not contain 'foobar', no substitution occurs, so output is unchanged.
🚀 Application
expert3:00remaining
How to swap two words on each line using sed?
You want to swap the first two words on each line of a file using sed. Which command achieves this?
Attempts:
2 left
💡 Hint
sed uses basic regular expressions; \w and \b are not supported by default.
✗ Incorrect
Option C uses basic regex supported by sed: \([^ ]*\) matches first word, \([^ ]*\) second word, then swaps them.