Sweet Search And Highlight Command

Been doing quite a bit of manipulating LaTeX files on the command line recently, and have a very sweet little command for searching for text in multiple files:

grep -r Hoffman */*.tex | less +/Hoffman

Where “Hoffman” is the search term which can of course be any regular expression.

The “less” command has a very convenient argument “+” which allows you to pass a search term in and will automatically highlight it for you.

The -r in grep recurses directories and */*.tex looks for all tex files. the | pipes the result to less.

sweet.

Share