Diff a1.txt a2.txt | grep 2011.
The name, “grep”, derives from the command used to perform a similar operation, using the Unix/Linux text editor ed:g/re/p.
When you search for boo, grep will match fooboo, boo123, barfoo35 and more. You can force the grep command to select only those lines containing matches that form whole words i.e. match only boo word.
Use the egrep command as follows:
$ egrep -w 'word1|word2' /path/to/file
The grep can report the number of times that the pattern has been matched for each file using -c (count) option:
$ grep -c 'word' /path/to/file
Pass the -n option to precede each line of output with the number of the line in the text file from which it was obtained:
$ grep -n 'root' /etc/passwd