Grep and ignore minified javascript
Asked Answered
C

3

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.

Cythera answered 9/5, 2012 at 22:26 Comment(0)
I
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 .

Into answered 5/6, 2012 at 17:4 Comment(0)
M
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."

Maricamarice answered 9/5, 2012 at 22:44 Comment(0)
L
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.

Lucerne answered 9/5, 2012 at 22:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.