Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

3 Answers 3

up vote 4 down vote accepted

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 
share|improve this answer
add comment
 grep -rin 'text' `find /path/to/directory -name wscript`
share|improve this answer
1  
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
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 '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
show 2 more comments
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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