0

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
1
  • @SatoKatsura thanks but it doesn't work...
    – dimas
    May 24, 2017 at 14:14

2 Answers 2

3

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
0
2

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

otherwise:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .