Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grep and ignore minified javascript

Tags:

grep

minify

ack

Is there a way to tell ack/grep to ignore minified Javascript? Those files have thousands of characters per line and screw up the search output.

like image 373
Kevin Burke Avatar asked May 09 '12 22:05

Kevin Burke


2 Answers

ack 1.x does not have a way to ignore minified javascript directly. This will be addressed in ack 2.0. We're working on it at http://github.com/petdance/ack2 .

like image 123
Andy Lester Avatar answered Oct 27 '22 10:10

Andy Lester


Try something like this:

grep foo $(find -name '*.js' -exec file {} \; | grep -v "long lines" | sed 's/:.*//')
  • find -name '*.js' finds all the .js files in the current directory and subdirectories.

  • Adding -exec file {} \; to the find command runs the file command on each result.

  • The results of file are piped into grep, and files listed as having "long lines" are removed from the results.

  • The descriptions from file are stripped off with sed, leaving only the filenames. These are the files grep will search for "foo."

like image 22
Dagg Nabbit Avatar answered Oct 27 '22 12:10

Dagg Nabbit