#!/bin/bash

# ideone boilerplate: run in temp dir 
t=$(mktemp -d -t ideone.XXXXXXXX) || exit trap 'rm -rf "$t"' ERR EXIT
cd "$t"

mkdir -p files/poo files/bar/quux
echo AAA |
tee files/poo/aaa.txt files/bar/aaa.txt >files/bar/quux/aaa.txt
echo BBB | tee files/bbb.txt files/poo/bbb.txt >files/bar/quux/bbb.txt
printf '%s\n' "aaa" "bBb" |
tee files/poo/aaabbb.txt files/bar/aaabbb.txt >files/bar/quux/aaabbb.txt

echo "*** grep | xargs grep | xargs"

grep -ilrZ "AAA" ./files/* |
xargs -r0 grep -Zil "BBB" |
xargs -r0 -i echo "{} match"

echo "*** find -exec -exec -exec"

find ./files -type f \
    -exec grep -qi "AAA" {} \; \
    -exec grep -qi "BBB" {} \; \
    -exec sh -c 'for f; do echo "$f matched"; done' _ {} +
