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.
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 .
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 thefind
command runs thefile
command on each result.The results of
file
are piped intogrep
, and files listed as having "long lines" are removed from the results.The descriptions from
file
are stripped off withsed
, leaving only the filenames. These are the filesgrep
will search for "foo."
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.
© 2022 - 2024 — McMap. All rights reserved.