Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?

share|improve this question
up vote 4 down vote accepted

man grep:

          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 
share|improve this answer
 grep -rin 'text' `find /path/to/directory -name wscript`
share|improve this answer
did'nt work man. – Vihaan Verma Sep 23 '12 at 4:46
Note that the quotes around the find command are backquotes not regular quotes. – Isaac Rabinovitch Sep 23 '12 at 5:02
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 '12 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. – Isaac Rabinovitch Sep 23 '12 at 22:20
Note that @Serge's answer is better than mine. I even upvotted it! – Isaac Rabinovitch Sep 23 '12 at 22:21
grep -rin 'your-text' /path/to/text/file/text-file.txt

It works only with text files, though.

share|improve this answer
That doesn't restrict the files by name. – Isaac Rabinovitch Sep 23 '12 at 5:43

You must log in to answer this question.

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