Last active
December 25, 2015 08:49
-
-
Save r10r/6949740 to your computer and use it in GitHub Desktop.
Combine grep and find to restrict search to certain files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Combine find and grep to search (source) files. | |
# Just for lazy typers ;) | |
# | |
# E.g limit grep to *.h and *.c: | |
# sgrep X509_verify_cert .c .h | |
find_args="" | |
for arg in $(echo $@ | cut -d' ' -f 2-); do | |
if [ -z "$find_args" ]; then | |
find_args="-name \*${arg}" | |
else | |
find_args="$find_args -or -name \*${arg}" | |
fi | |
done | |
command="grep -Rn '$1' \$(find . -type f -and \( $find_args \))" | |
eval "$command" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment