Originally Posted by chrism01
note that grep takes a filename as an arg, so cat is unneeded
grep -P "\b(first|second)\b" datafile
grep -P "\bfirst\b" datafile | grep -P "\bsecond\b"
I'm sure you can imagine why I use "cat" in a case where there may be more than one "grep" call present on a line. This is, after all, a newbie discussion group, where aesthetics and clarity of expression matter at least as much as issues of efficiency.
To decide how much clarity of expression matters to newbies, one need only read the interminable threads about the syntax of "xargs", many of which expire more from exhaustion than resolution.