Wednesday, June 9, 2010

grep ... -x .. exact line match only


$cat example.txt
A for Apple.
B for Baby.
C for Cat.
D for Donkey.
$grep A example.txt
A for Apple.
$grep -x A example.txt
$grep -x A for Apple. example.txt
grep: for: No such file or directory
grep: Apple.: No such file or directory
$grep -x "A for Apple." example.txt
A for Apple.
$grep -x "A for Apple" example.txt
$


grep -x option
Select only those matches that exactly match the whole line. (-x is specified by POSIX.)

source : debian grep manual.



case 'x':
match_lines = 1;
break;

source : debian GNU grep.



Research Related Paper.

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.85.1663&rep=rep1&type=pdf