It would be cool if grep could get an option to print the regexp which matched in place of the matching lines. E.g. $ cat <<_eof > patterns .o. .a. _eof $ echo foo | egrep --file=patterns --print-matching-regexp .o. $ echo foo | egrep --file=patterns --print-matching-regexp-lineno 1 $ echo bar | egrep --file=patterns --print-matching-regexp .a. $ echo bar | egrep --file=patterns --print-matching-regexp-lineno 2 $ echo foo | egrep --file=patterns --file=patterns2 --print-matching-regexp patterns:.o. $ echo foo | egrep --file=patterns --file=patterns2 --print-matching-regexp-lineno patterns:1 $ echo bar | egrep --file=patterns --file=patterns2 --print-matching-regexp patterns:.a. $ echo bar | egrep --file=patterns --file=patterns2 --print-matching-regexp-lineno patterns:2
Interesting idea. OTOH it's yet another option for which grep |grep doesn't mean "lines that match both REs". Did you try --color?
also sprach Justin Pryzby <justinpryzby@users.sourceforge.net> [2008.03.03.1705 +0100]: Huh? I use it all the time, but it's not useful to be used from scripts, nor does it tell me which regexp actually matched.
I divide the grep options into two categories, determined by whether you can do pipe grep output into a 2nd grep and get precisely those lines that match both REs. grep -e a -e b and grep -Ee 'a\|b' exit to select lines that match either. grep -EFGPefiwxh allow that. OTOH grep -ABCbnHoclL don't.