Challenge - 5 Problems
Sed Substitution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
Output of sed substitution with global flag
What is the output of this command when run on the input string
apple apple apple?Linux CLI
echo "apple apple apple" | sed 's/apple/orange/g'
Attempts:
2 left
💡 Hint
The
g flag means replace all occurrences in each line.✗ Incorrect
The
s/apple/orange/g command replaces every 'apple' with 'orange' in the input line.💻 Command Output
intermediate1:30remaining
Effect of sed substitution without global flag
What is the output of this command when run on the input string
banana banana banana?Linux CLI
echo "banana banana banana" | sed 's/banana/grape/'
Attempts:
2 left
💡 Hint
Without the
g flag, only the first match is replaced.✗ Incorrect
The
s/banana/grape/ command replaces only the first 'banana' in the line.📝 Syntax
advanced2:00remaining
Identify the correct sed substitution syntax
Which option shows the correct syntax to replace all occurrences of
cat with dog in a file named pets.txt?Attempts:
2 left
💡 Hint
The substitution command should be enclosed in single quotes with the s///g format.
✗ Incorrect
Option A uses the correct syntax with single quotes and the substitution command.
💻 Command Output
advanced1:30remaining
Output of sed substitution with special characters
What is the output of this command?
Linux CLI
echo "path/to/file" | sed 's/\//-/g'
Attempts:
2 left
💡 Hint
The slash character is escaped to be replaced by a dash globally.
✗ Incorrect
The command replaces all slashes '/' with dashes '-' in the input string.
💻 Command Output
expert2:30remaining
Result of sed substitution with capture groups and backreferences
What is the output of this command?
Linux CLI
echo "2024-06-15" | sed 's/\([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\)/\3\/\2\/\1/'
Attempts:
2 left
💡 Hint
Backreferences \1, \2, \3 refer to year, month, day respectively.
✗ Incorrect
The command rearranges the date from YYYY-MM-DD to DD/MM/YYYY format using capture groups.