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
dimas
  • 1,151
  • 4
  • 22
  • 33

2 Answers2

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
Satō Katsura
  • 13,368
  • 2
  • 31
  • 50
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
Eric Renouf
  • 18,431