I'm looking for all the files in a directory that contain "AAA" and "BBB". I then want to modify/do stuff with each of the found files. The file names do contain spaces.
grep piping to grep would seem simple but requires the xargs to function correctly.
The multiple match functionality in grep (from what I can tell) is only for "AAA" or "BBB".
What I've got is:
for FILENAME in "$(grep -ilrZ "AAA" ./files/* | xargs -0 grep -ilr "BBB")"
do
echo "$FILENAME"
echo "match"
done
However, this treats the list as files (including the newlines) as a single entity (i.e. "match" will only print once).
Removing the double quotes from the for sub-shell means every space is a new thing to be looped over, which breaks up filenames.