Skip to content

Instantly share code, notes, and snippets.

@junquera
Last active March 25, 2019 15:36
Show Gist options
  • Save junquera/4a887af3a65a6ba6a8c89f5b18e4d9f0 to your computer and use it in GitHub Desktop.
Save junquera/4a887af3a65a6ba6a8c89f5b18e4d9f0 to your computer and use it in GitHub Desktop.
Find a text occurrence in all the files in a path
#!/bin/bash
PATH_TO_FIND="$1"
TEXT_TO_FIND="$2"
find $1 -type f |
while read f; do
if [ $(grep $2 "$f" | wc -l) -gt 0 ]; then
echo $f
else
if [ $(echo "$f" | grep $2 | wc -l) -gt 0 ]; then
echo $f
fi;
fi;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment