grep exact match code example
Example 1: grep not match
Just filter your output with:
grep -v "excluded_pattern"
Example to get all not txt files in current directory.
ls | grep -v .txt
Example 2: grep third match
grep -m2 "two" in-file.txt | tail -n1
Example 3: grep first match
Just combine grep with head command for filtering only the first match as:
grep "match" | head -n 1
Example 4: grep or match
$ grep "PATTERN1\|PATTERN2" FILE
$ grep -E "PATTERN1|PATTERN2" FILE
$ grep -e PATTERN1 -e PATTERN2 FILE
$ egrep "PATTERN1|PATTERN2" FILE