grep(Global Regular Expression Print) is a powerful command-line tool that searches for specified patterns in files or text streams. It’s like having a digital magnifying glass that can find any text pattern you're looking for across one or multiple files.
>Synopsis
grep [options]pattern [files]
>Options
-i
-i (ignore case): Ignores case while searching for the pattern.
Example 1:
-zsh
> echo "Hello World" | grep -i "hello"
Hello World
!!! Grep normally reqires a file for input, but beacuse is allowed and for ease of explanations is used echo !!!
-r
-r (recursive): Searches files in directories and subdirectories.
Example 2:
-zsh
> grep -r "pattern" ./directory/
./directory/file.txt: pattern
-v
-v (invert match): Displays all lines that do not match the pattern.