Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to replace the first occurrence of 'apple' with 'orange' in the input text.
Linux CLI
sed '[1]/apple/orange/' file.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'y' instead of 's' which is for transliteration, not substitution.
Using 'd' which deletes lines, not substitutes text.
✗ Incorrect
The 's' command in sed is used for substitution. Here, it replaces 'apple' with 'orange'.
2fill in blank
mediumComplete the code to replace all occurrences of 'cat' with 'dog' in the input text.
Linux CLI
sed '[1]/cat/dog/g' file.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the 'g' flag, which replaces only the first occurrence per line.
Using 'd' which deletes lines instead of substituting text.
✗ Incorrect
The 's' command with the 'g' flag replaces all occurrences of 'cat' with 'dog' in each line.
3fill in blank
hardFix the error in the sed command to replace 'blue' with 'red' only on lines containing 'sky'.
Linux CLI
sed '/sky/ [1] blue/red/' file.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'd' which deletes lines instead of substituting text.
Omitting the 's' command causing syntax error.
✗ Incorrect
The substitution command 's' must be used after the address '/sky/' to replace 'blue' with 'red' only on matching lines.
4fill in blank
hardFill both blanks to replace 'dog' with 'cat' only on lines starting with 'Pet'.
Linux CLI
sed '[1]/^Pet/ [2] dog/cat/' file.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using '-n' causes all lines to print, not just modified ones.
Using 'p' instead of 's' for substitution.
✗ Incorrect
The '-n' option suppresses automatic printing, and 's' performs substitution on lines starting with 'Pet'.
5fill in blank
hardFill all three blanks to replace 'apple' with 'orange' globally and print only changed lines.
Linux CLI
sed '[1]' file.txt | sed '[2]/apple/[3]/orange/gp'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting '-n' causes all lines to print.
Using 'd' or 'p' incorrectly instead of 's' for substitution.
✗ Incorrect
The first sed suppresses output with '-n'. The second sed uses '-n' and 's' with 'gp' to substitute globally and print changed lines.