0
0
Bash Scriptingscripting~10 mins

Why file I/O is core to scripting in Bash Scripting - Test Your Understanding

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

Complete the code to read the contents of a file named 'data.txt' and display it.

Bash Scripting
cat [1]
Drag options to blanks, or click blank then click option'
Aoutput.txt
Binput.txt
Cfile.txt
Ddata.txt
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong file name.
Forgetting to specify the file name after 'cat'.
2fill in blank
medium

Complete the code to write the text 'Hello World' into a file named 'greeting.txt'.

Bash Scripting
echo "Hello World" > [1]
Drag options to blanks, or click blank then click option'
Agreeting.txt
Boutput.txt
Chello.txt
Dmessage.txt
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong file name.
Using the append operator >> instead of overwrite >.
3fill in blank
hard

Fix the error in the code to append the text 'New line' to the file 'log.txt'.

Bash Scripting
echo "New line" [1] log.txt
Drag options to blanks, or click blank then click option'
A|
B>
C>>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using > which overwrites the file.
Using input redirection < or pipe | incorrectly.
4fill in blank
hard

Fill both blanks to create a script that reads 'input.txt', filters lines containing 'error', and writes them to 'errors.log'.

Bash Scripting
grep [1] [2] > errors.log
Drag options to blanks, or click blank then click option'
A"error"
Binput.txt
Coutput.txt
D"warning"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pattern or file name.
Confusing input and output files.
5fill in blank
hard

Fill all three blanks to create a script that counts lines in 'data.csv' containing the word 'success' and saves the count to 'count.txt'.

Bash Scripting
grep [1] [2] | wc -l > [3]
Drag options to blanks, or click blank then click option'
A"success"
Bdata.csv
Ccount.txt
Derrors.log
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file names.
Forgetting to redirect output to the count file.