I'd like to use grep to recursively search through a directory, using patterns listed in a file, then store each result in its own file for reference later.
I made an attempt (using this question as a guide) and came up with:
#!/bin/bash mkdir -p grep_results # For storing results echo "Performing grep searches.." while IFS='' read -r line || [[ -n "$line" ]]; do echo "Seaching for $line.." grep -r "$line" --exclude-dir=grep_results . > ./grep_results/"$line"_infile.txt done echo "Done."
However, when I run it, the console hangs until I hit CTRL-C:
$ bash grep_search.sh search_terms.txt Performing grep searches..
Where is the issue with this script? Or am I approaching this wrong?