Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to search for the word 'error' in the file 'log.txt'.
Bash Scripting
grep [1] log.txt Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an option like -i without the pattern.
Forgetting to put the search word in quotes.
✗ Incorrect
The correct syntax to search for the word 'error' is to provide it as a quoted string argument to grep.
2fill in blank
mediumComplete the code to search for the word 'fail' in 'report.txt' ignoring case.
Bash Scripting
grep [1] "fail" report.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-v' which inverts the match.
Using '-c' which counts matches instead of showing them.
✗ Incorrect
The '-i' option makes grep ignore case when searching.
3fill in blank
hardFix the error in the script to count lines containing 'warning' in 'system.log'.
Bash Scripting
count=$(grep [1] system.log | wc -l)
echo $count Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-c' as a pattern instead of an option.
Putting options inside quotes as pattern.
✗ Incorrect
The pattern 'warning' should be given as a string to grep. Using '-c' as a pattern is incorrect here.
4fill in blank
hardFill both blanks to create a script that searches recursively for 'TODO' in the current directory and shows line numbers.
Bash Scripting
grep [1] [2] "TODO" .
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-v' which inverts the match.
Using '-i' which ignores case but is not required here.
✗ Incorrect
The '-r' option searches recursively, and '-n' shows line numbers in the output.
5fill in blank
hardFill all three blanks to create a script that searches for lines NOT containing 'debug' in 'app.log' and counts them.
Bash Scripting
grep [1] [2] "debug" app.log | wc [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-c' which counts bytes instead of lines.
Forgetting to invert the match with '-v'.
✗ Incorrect
The '-v' option inverts the match to exclude 'debug'. '-i' ignores case. '-c' counts the matching lines with wc.