Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep specific filetypes on MAC

Tags:

grep

macos

I have a Mac OS X snow leopard. I am using the xterm terminal to grep specific string using this command grep -R --color=auto setHeader *.js but when I run this command I get the error saying

grep: \*.js: No such file or directory

So my question is how can I grep for a specific filetype on Mac?

like image 389
Amrish Avatar asked Mar 21 '11 15:03

Amrish


3 Answers

This one works for me on Mac OS 10.8:

grep --include=*.js -r setHeader .
like image 161
yegor256 Avatar answered Oct 09 '22 02:10

yegor256


The best way to do that is to combine the find and the grep command:

find . -name "*.js" -exec grep --color=auto setHeader {} \;
like image 22
Laurent Etiemble Avatar answered Oct 09 '22 02:10

Laurent Etiemble


grep --include=*.js -R . --color=auto setHeader

Since the example given uses "file type = file extension", this should just work.

like image 33
Andy Finkenstadt Avatar answered Oct 09 '22 03:10

Andy Finkenstadt