0
0
Linux CLIscripting~10 mins

sed substitution 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 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'
Ad
By
Cs
Dp
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.
2fill in blank
medium

Complete 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'
As
Bd
Cy
Dp
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.
3fill in blank
hard

Fix 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'
Ad
Bs
Cp
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'd' which deletes lines instead of substituting text.
Omitting the 's' command causing syntax error.
4fill in blank
hard

Fill 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'
A-n
Bs
Dp
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.
5fill in blank
hard

Fill 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'
A-n
Cs
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting '-n' causes all lines to print.
Using 'd' or 'p' incorrectly instead of 's' for substitution.