Skip to content

Instantly share code, notes, and snippets.

@debussyman
Last active December 30, 2015 07:39
Show Gist options
  • Save debussyman/7797206 to your computer and use it in GitHub Desktop.
Save debussyman/7797206 to your computer and use it in GitHub Desktop.
Simple script that wraps grep recursive find
#!/bin/bash
export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
function usage
{
echo "usage: gfind \"search string\" [-e file extension ]"
}
filetype=
searchstring=
while [ "$1" != "" ]; do
case $1 in
-e | --extension ) shift
filetype=$1
;;
-h | --help ) usage
exit
;;
* ) searchstring=$1
;;
esac
shift
done
if [ -z "$searchstring" ]; then
usage
exit
fi
if [ "$filetype" != "" ]; then
find . -type f -name $filetype -exec grep -A 1 -B 1 -n "$searchstring" '{}' \; -print
else
find . -type f -exec grep -A 1 -B 1 -n "$searchstring" '{}' \; -print
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment