0

I have some .sh and .bat files in a directory. I want to list only the .sh files that has the word "JAVA_HOME".

I tried grep -rl "JAVA_HOME" | grep "*.sh", grep -rl "JAVA_HOME" *.sh and few other random things, but none of them worked. Can someone help me with this? Thank you.

  • Related: https://unix.stackexchange.com/q/185951/117549 and https://unix.stackexchange.com/q/82139/117549 and https://unix.stackexchange.com/q/336921/117549 and https://unix.stackexchange.com/q/500243/117549 and https://unix.stackexchange.com/q/14498/117549 and https://unix.stackexchange.com/q/7383/117549 – Jeff Schaller Dec 27 '19 at 19:46

1 Answers1

5

Since you appear to be using GNU grep already (with -r), add the --include option to search only those matching filenames:

grep -rl --include='*.sh' "JAVA_HOME"
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255