look for a text pattern in files defined by a pattern. First argument is passed to the find command, second one to the grep
./find_n_grep.sh '*.py' 'dict'
more over, it sort by date.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/usr/bin/env zsh
tmp_file="/tmp/_unsorted_find_n_grep"
echo "--- find <$2> in <$1>" > $tmp_file
find . -follow -iname "$1" | while read file
do
timestamp=$(ls -l --time-style=+"%Y-%m-%d %H:%M:%S" "$file" | gawk '{print $6, $7}')
linestack=${(@f)$(egrep "$2" "$file")}
for line in $linestack
do
echo "$timestamp $file: $line" >> $tmp_file
done
done
cat $tmp_file | sort
rm $tmp_file
|