Why does find . -name "*.xml" | xargs grep FOO returns matchs with filenames, while find . -name "*.xml" | xargs -i -sh -c "grep FOO {}" doesn't?
Unless it's a typo in posting your question there shouldn't be a hyphen before sh:
The reason you don't get filenames in the output is that grep is being run with a single file as an argument. To force filename output use -H.
find . -name "*.xml" | xargs -I {} sh -c "grep -H FOO {}"
Also, -i for xargs was deprecated around version 4.2.9. You should use -I {}.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With