I found an example which uses a combination of find and xarg or exec to search a specific pattern from the result see link here.
However I'd like to use the result of find command and use it as search pattern for grep. Something like command below but am not sure how to construct it.

find . -name "*.cgi" -printf '%f\n' | cut -d. -f1 | xarg grep 'find_result' *.html
  • @SatoKatsura thanks but it doesn't work...
    – dimas
    May 24 '17 at 14:14

Assuming GNU grep, and assuming your filenames don't have embedded newlines:

find . -name '*.cgi' -printf '%f\n' | cut -d. -f1 | sort -u | fgrep -f - *.html

You don't need xargs here, you can just have grep read the pattern list from stdin:

with GNU find:

find . -name '*cgi' -printf '%f\n' | grep -f - *html


find . -name '*cgi' | cut -f2- -d/ | grep -f - *html
  • thanks Eric... this one works as well but I have to give the points to sato
    – dimas
    May 24 '17 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.