Created
January 15, 2016 23:19
-
-
Save josecanciani/9c182889557254ded5a0 to your computer and use it in GitHub Desktop.
google: search for patterns in all files
This file contains hidden or 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/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