vcgrep prints a summary of all the matches of a regular-expression capture group within input files. Simple terminal visualization of the progress and results is provided. Use it to easily show the frequency of status codes from apache access logs, or the frequency of words in a text document.
vcgrep requires node 0.10 or later.
npm install -g vcgrep
Frequency of status codes in an apache access log:
vcgrep '(\d+)\W+\d+$' test/sample-access.log
Frequency of words found in a text document:
vcgrep -g '(\w+)+' README.md
Frequency of words found in js documents using the full page card progress mode:
vcgrep -p card -o none -g -i --include '*.js' '(\w+)+' lib
Usage: vcgrep [OPTIONS] PATTERN FILES...
The pattern
is a regular expression containing at least one capture group.
For more details on the JavaScript regular expression syntax, see: MDN
--help Prints a summary of the usage
--verbose, -v Verbose logging
--version Show version number
--exclude Exclude files that match the wildcard
--include include only files that match the wildcard
--global, -g Multiple matches per line are considered
--ignore-case, -i Ignore case for determining capture key
--head, -h Limit results to the most frequent n entries
--output, -o Output format, one of: count,none,plain,json,histogram [default: "histogram"]
--progress, -p Progress feedback, one of: card,none,line [default: "line"]
The searching, progress, and report output features are available to NodeJS modules through an API module.
For examples of how to use the API see: lib/api.js
var vcgrep = require('vcgrep');
vcgrep.searchFiles(/(\w+)+/g, ['README.md'], {progress: 'none'}, function(err, matches) {
vcgrep.writeOutput('histogram', matches);
console.log('Found '+matches.total+' hits across: '+matches.totalFiles+' files');
});
- --exclude file wildcard option
- count output option with total matches and files
- Progress API now event based
- Change ignore case flag to --ignore-case from --ignore to match grep
- Pass options to search api as object
- 'card' full page progress
- --ignore case of capture key
- Introduce simple API entry point for direct use by NodeJS modules
- Process exit code, 0 when matches found, 1 no matches
- Initial feature set
vcgrep is released under the MIT licence.
David Jones