can you specify which files to grep search?
i have a complex directory with many files and many subdirectories. I would like to grep for patterns in some php files, html files, javascript files, while ignoring .gz files, image files, and files in certain directories.
is there a way to do this? i have tried the --include and --exclude flags for grep but they don't appear a) to support multiple file extensions in a single expression b) to allow you to exclude entire subdirectories. I'm guessing that there might be some way to create a list of the files i want searched and perhaps pipe that to the grep command? that would be awesome. if someone could help me, i would appreciate it. |
try:
grep -i '<string>' | ./*.php *.html *.js that would search only php, html, and js files while ignoring anything else in the directory. |
thanks for the suggestion...i need it to recurse subdirs (excepting ones i want to specifically exclude).
the ideal situation would be to generate a file list and only check those files.. |
I think this can do what you ask :
find . -type f \( -name \*.php -o -name \*.html -o -name \*.js \) | grep -v -e <dir1_to_exclude> -e <dir2_to_exclude> | xargs grep --with-filename <string_to_search> Hope this helps. |
wow!
pretty gnarly. i will give that a try. THANKS! |
All times are GMT -5. The time now is 08:46 PM. |