Tsallaka zuwa abun ciki
Justice Tech School

grep Searches Text

grep finds lines that match a pattern. Options: -i ignore case, -v invert, -n numbers, -c count, -r recursive, -E extended regex and -o only matches.

Example
text=$(printf "apple pie\nBanana split\ncherry tart\napple crumble")
echo "$text" | grep apple
echo "$text" | grep -ic "banana"
echo "$text" | grep -v apple
echo "$text" | grep -n tart
echo "ab12cd345" | grep -oE "[0-9]+"

Result

apple pie
apple crumble
1
Banana split
cherry tart
3:cherry tart
12
345

Exercise

Ignore case.

grep  word file

Quiz Test

Which inverts a match?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.