Skip to content

Instantly share code, notes, and snippets.

@josecanciani
Created January 15, 2016 23:19
Show Gist options
  • Save josecanciani/9c182889557254ded5a0 to your computer and use it in GitHub Desktop.
Save josecanciani/9c182889557254ded5a0 to your computer and use it in GitHub Desktop.
google: search for patterns in all files
#!/bin/bash
# A simple bash script that search all files in the current directory finding the words you put on input
# Searches all lines of the file
# Usage: google hello world
if [ -f .google ]
then
rm -f .google
fi
WORDCOUNT=0
for word in "$@"
do
((WORDCOUNT++))
rgrep --exclude-dir=packs $word * | cut -d ':' -f 1 | sort | uniq >> .google
done
if [ -f .google ]
then
sort .google | uniq --count | while read result
do
read -a r <<<"$result"
if [ ${r[0]} -eq $WORDCOUNT ]
then
echo ${r[1]}
fi
done
rm -f .google
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment