fork download
  1. #!/bin/bash
  2.  
  3. # ideone boilerplate: run in temp dir
  4. t=$(mktemp -d -t ideone.XXXXXXXX) || exit trap 'rm -rf "$t"' ERR EXIT
  5. cd "$t"
  6.  
  7. mkdir -p files/poo files/bar/quux
  8. echo AAA |
  9. tee files/poo/aaa.txt files/bar/aaa.txt >files/bar/quux/aaa.txt
  10. echo BBB | tee files/bbb.txt files/poo/bbb.txt >files/bar/quux/bbb.txt
  11. printf '%s\n' "aaa" "bBb" |
  12. tee files/poo/aaabbb.txt files/bar/aaabbb.txt >files/bar/quux/aaabbb.txt
  13.  
  14. echo "*** grep | xargs grep | xargs"
  15.  
  16. grep -ilrZ "AAA" ./files/* |
  17. xargs -r0 grep -Zil "BBB" |
  18. xargs -r0 -i echo "{} match"
  19.  
  20. echo "*** find -exec -exec -exec"
  21.  
  22. find ./files -type f \
  23. -exec grep -qi "AAA" {} \; \
  24. -exec grep -qi "BBB" {} \; \
  25. -exec sh -c 'for f; do echo "$f matched"; done' _ {} +
  26.  
Success #stdin #stdout 0.03s 5476KB
stdin
Standard input is empty
stdout
*** grep | xargs grep | xargs
./files/bar/aaabbb.txt match
./files/bar/quux/aaabbb.txt match
./files/poo/aaabbb.txt match
*** find -exec -exec -exec
./files/bar/aaabbb.txt matched
./files/bar/quux/aaabbb.txt matched
./files/poo/aaabbb.txt matched