Mission 3 of 5
Grep: Search Master
Find the important lines in a noisy application log.
Search text confidently with exact matches, case-insensitive matches, inverted matches, and simple regex.
Mental model
Understand what is happening
grep prints lines matching a pattern.
Regex is a pattern language; start small.
-r searches folders recursively.
Guided lab
Work through the mission
Basic grep
Finds matching and non-matching lines.
cd ~/linux-practice
echo -e 'Apple\napple\nAPPLE\nBanana\napricot' > fruits.txt
grep -i 'apple' fruits.txt
grep -v 'apple' fruits.txtRegex anchors
Uses start, end, and OR matching.
grep '^A' fruits.txt
grep 'e#x27; fruits.txt
grep -E 'apple|Banana' fruits.txtRecursive search
Searches through folders.
mkdir -p projects/search-demo
echo 'secret pattern' > projects/search-demo/file.txt
grep -r 'pattern' projectsCheckpoint
Verify the mission
Only the intended log lines appear.
Try it yourself
One step without a recipe
Create ips.txt and find addresses starting with 192.168. Use grep -n to show line numbers.
Need a hint?
Start every grep session with the simplest pattern that works, then add complexity. `grep 'error'` before `grep -E 'error|warning'`. Get the basics right, then layer on regex. Trying to write the perfect pattern on the first attempt is how you end up staring at a blank prompt for ten minutes.
Explain it back
Before you move on
- Which option ignores case?
- What does ^ mean in a regex?