Last Updated: February 25, 2016
·
808
· arichiardi

Bash, grep string in file with file name and line number.

Not a very new pro tip, but always very useful.

This command tries to find the input string in the specified files (or all files in a folder with *).
Here is the break-down of the parameters:

  • -r stands for recursive
  • -n for showing line numbers
  • -w finds whole words

It shows file name, line and match in this order.

grep -rnw "tests" ./src/sicp_clojure/*

./src/sicp_clojure/1_1_exercises.clj:12:; See tests at the bottom.
./src/sicp_clojure/1_1_exercises.clj:162:(t/deftest tests
./src/sicp_clojure/1_1_samples.clj:41:(t/deftest tests