1️⃣grep command
usage of grep commands
`grep - global regular expression print`
Searches for particular string/keyword from a file and print lines matching a pattern
Checks line by line and print lines matching a pattern
Sample file

grep [pattern] [filename]

grep -i “keyword” filename
→ Ignore case of the pattern

grep -v “keyword” filename
→ Show all records except the patterngrep -c “keyword” file
→ count number of lines in which word is present

grep -w “keyword” file
→ exact match of a word

grep -n “keyword” file
→ also prints the line number

grep “keyword” file1 file2 file3 ……
→ search in multiple files

grep -e “keyword” -e “keyword” -e “keyword” file
→ search for multiple keywords in a file

grep -e “keyword” -e “keyword” -e “keyword” file1 file2 …..
grep -l “keyword” file1 file2 file3
…..
→ only get file name in which the word is present

grep “^keyword” file
→ print matching line which starts from matching keywordgrep “keyword$” file
grep -R “keyword” file
→ find in every file in a directory recursively

egrep “key1|key2|key3” filename

grep -q “keyword” filename
- search but don't print on terminal
Check the status by echo $? → exit status
grep -s “keyword” filename
→ suppress errorsUse to search files →
ls | grep rc

Last updated