0
0
Bash Scriptingscripting~10 mins

grep in scripts in Bash Scripting - Interactive Code Practice

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

Complete 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'
A"error"
B-r
C-v
D-i
Attempts:
3 left
💡 Hint
Common Mistakes
Using an option like -i without the pattern.
Forgetting to put the search word in quotes.
2fill in blank
medium

Complete 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'
A-r
B-v
C-i
D-c
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-v' which inverts the match.
Using '-c' which counts matches instead of showing them.
3fill in blank
hard

Fix 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'
A"-c"
B"-i"
C"-v"
D"warning"
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-c' as a pattern instead of an option.
Putting options inside quotes as pattern.
4fill in blank
hard

Fill 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'
A-r
B-n
C-i
D-v
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-v' which inverts the match.
Using '-i' which ignores case but is not required here.
5fill in blank
hard

Fill 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'
A-v
B-i
C-l
D-c
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-c' which counts bytes instead of lines.
Forgetting to invert the match with '-v'.