3

I know about

grep -rin 'text' /path/to/direcotry

But I dont want to look up in all the files . I just need to check for occurrence of 'text' in all files named wscript. How can that be done ?

3 Answers 3

4

man grep:

   --include=GLOB
          Search  only  files whose base name matches GLOB (using wildcard
          matching as described under --exclude).

so try this:

grep -rin --include=wscript 'text' /path/to/files 
2
 grep -rin 'text' `find /path/to/directory -name wscript`
7
  • 1
    did'nt work man. Sep 23, 2012 at 4:46
  • Note that the quotes around the find command are backquotes not regular quotes. Sep 23, 2012 at 5:02
  • 1
    The backticks are hard to read, I'd suggest using $() instead. I'd also recommend not to use command substitution for parsing find output, it'll likely break. A safer alternative would be to pipe it to xargs in a null-delimited format.
    – slhck
    Sep 23, 2012 at 8:14
  • I rolled this back to my version. @slhck 's version is fine, but it's completely different, and belongs in its own answer. Sep 23, 2012 at 22:20
  • Note that @Serge's answer is better than mine. I even upvotted it! Sep 23, 2012 at 22:21
0
grep -rin 'your-text' /path/to/text/file/text-file.txt

It works only with text files, though.

1
  • That doesn't restrict the files by name. Sep 23, 2012 at 5:43

You must log in to answer this question.

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