When finding a string in files within a directory, one can use this:
grep -r "searchstring" dir/subdir/ > listofoccurrences.txt
For brevity sake one can enter the intended directory and use this:
grep -r "searchstring" . > listofoccurrences.txt
which as I found out leads to an endless loop, because listofoccurrences.txt also contains the searchstring and will therefore be perpetually augmented with the searchstring.
Are there ways, such as options or directives, one can use to prevent endless loops with recursive greps other than staying away from the directory to search in?