There is a tool named
ack. You can find it at http://beyondgrep.com and it is indeed a tool beyond grep. Its most common use is the filling of that role of
find . -name "*.java" --print | xargs grep clazz or the like. Because we do that all the time.
ack clazz and you get the output. Searches the proper files (doesn't bother trying to grep binaries) and gives a nice color output too.
If you use it with the
--passthru option it will print the entire input stream, highlighting the matched regions in color.
--passthru Print all lines, whether matching or not
As the documentation states if
- is used for the file, it will take STDIN:
If any files or directories are specified, then
only those files and directories are checked. ack may also search
STDIN, but only if no file or directory arguments are specified,
or if one of them is "-".
Thus, pardon the
cat abuse (and the pun - see below) you can have it :
$ cat file | ack --passthru pattern
$ cat file | ack --passthru pattern -
This will take the output of the pipe, and send it through
ack which will print all the lines (with
--passthru) with the pattern being highlighted.
This is exactly the tool you are after (and a bit more). It is a standard package for many package managers. See http://beyondgrep.com/install/ for your favorite.
U ack --thpppt!
(If you don't recognize it, thats Bill the Cat though the image search might also help - don't click on the Miley Cyrus set)