6

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.

Kevin Burke
  • 61,194
  • 76
  • 188
  • 305

3 Answers3

4

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 .

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
1

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."

Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
0

Depends if you can somehow indicate which files should be excluded. If you follow the .min.js convention, for instance, then it is a simple matter of just making sure these files are not searched. Otherwise no, grep does not have a --maximum-number-of-characters-per-line-to-count-as-a-match option.

carlpett
  • 12,203
  • 5
  • 48
  • 82