Complete the code to read the contents of a file named 'data.txt' and display it.
cat [1]The cat command reads and displays the contents of the specified file. Here, we want to read 'data.txt'.
Complete the code to write the text 'Hello World' into a file named 'greeting.txt'.
echo "Hello World" > [1]
>> instead of overwrite >.The echo command outputs text. Using > redirects this output into the specified file. Here, we want to write into 'greeting.txt'.
Fix the error in the code to append the text 'New line' to the file 'log.txt'.
echo "New line" [1] log.txt
> which overwrites the file.< or pipe | incorrectly.The >> operator appends text to a file without overwriting existing content. Using > would overwrite the file.
Fill both blanks to create a script that reads 'input.txt', filters lines containing 'error', and writes them to 'errors.log'.
grep [1] [2] > errors.log
The grep command searches for a pattern in a file. Here, we search for the word 'error' in 'input.txt' and redirect the matching lines to 'errors.log'.
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'.
grep [1] [2] | wc -l > [3]
This command searches for 'success' in 'data.csv', counts the matching lines with wc -l, and writes the count to 'count.txt'.