0
0
Linux CLIscripting~10 mins

sed (stream editor) basics in Linux CLI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
As/apple/orange/g
Br/apple/orange/g
Cd/apple/orange/g
Di/apple/orange/g
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r' instead of 's' for substitution.
Forgetting the 'g' flag to replace all occurrences.
2fill in blank
medium

Complete 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'
Aorange
Bbanana
Capple
Dgrape
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong word inside the pattern.
Omitting the 'd' command to delete lines.
3fill in blank
hard

Fix 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'
A2-4
B2;4
C2,4
D2.4
Attempts:
3 left
💡 Hint
Common Mistakes
Using a dash '-' instead of a comma ',' for range.
Using semicolon or dot which are invalid for ranges.
4fill in blank
hard

Fill 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'
Apet
Bcat
Cdog
Danimal
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the pattern and the word to replace.
Using 'dog' as the pattern to match instead of 'cat'.
5fill in blank
hard

Fill 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'
A$
Ba
CEnd of file
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'i' instead of 'a' which inserts before the line.
Not using '$' to target the last line.