4 ms·
search - Keyword search without an index over a directory of text files ('.' or $ROOT): #!/usr/bin/zsh # Search a directory for files containing all of
by akkartik 3y ago
search - Keyword search without an index over a directory of text files ('.'
or $ROOT):
#!/usr/bin/zsh
# Search a directory for files containing all of the given keywords.
DIR=`mktemp -d`
ROOT=${ROOT:-.}
# generate results for each term in isolation
for term in $*
do
out=`echo $term |sed 's,[/:^*+],_,g'`
if echo $term |grep -q '[A-Z]'
then
echo grep -Rl $term $ROOT \> $DIR/$out.list >&2
eval grep -Rl $term $ROOT > $DIR/$out.list
else
echo grep -Ril $term $ROOT \> $DIR/$out.list >&2
eval grep -Ril $term $ROOT > $DIR/$out.list
fi
done
# generate results containing all terms
cat $DIR/*.list |sort |uniq -c |grep " $# " |column 2