Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to replace the word 'apple' with 'orange' in the file fruits.txt.
Linux CLI
sed '[1]' fruits.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r' instead of 's' for substitution.
Forgetting the 'g' flag to replace all occurrences.
✗ Incorrect
The 's' command in sed is used for substitution. 's/apple/orange/g' replaces all occurrences of 'apple' with 'orange'.
2fill in blank
mediumComplete the code to delete all lines containing the word 'banana' from the file fruits.txt.
Linux CLI
sed '/[1]/d' fruits.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong word inside the pattern.
Omitting the 'd' command to delete lines.
✗ Incorrect
The command '/banana/d' tells sed to delete lines containing 'banana'.
3fill in blank
hardFix the error in the code to print only lines 2 to 4 from the file fruits.txt.
Linux CLI
sed -n '[1]p' fruits.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a dash '-' instead of a comma ',' for range.
Using semicolon or dot which are invalid for ranges.
✗ Incorrect
The correct range syntax in sed is '2,4' to specify lines 2 through 4.
4fill in blank
hardFill both blanks to replace the first occurrence of 'cat' with 'dog' only on lines containing 'pet' in the file animals.txt.
Linux CLI
sed '/[1]/s/[2]/dog/' animals.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the pattern and the word to replace.
Using 'dog' as the pattern to match instead of 'cat'.
✗ Incorrect
The command '/pet/s/cat/dog/' replaces the first 'cat' with 'dog' on those lines.
5fill in blank
hardFill all three blanks to append the line 'End of file' after the last line of the file report.txt.
Linux CLI
sed '[1][2]\ [3]' report.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'i' instead of 'a' which inserts before the line.
Not using '$' to target the last line.
✗ Incorrect
The command '$a\nEnd of file' (newline after 'a') tells sed to append 'End of file' after the last line ($) of the file.