1.0.9 • Published 6 years ago
@apexearth/egrep v1.0.9
egrep
egrep for Node.js (Extended Global Regular Expressions Print)
Installation
Use with Node.js
$ npm install @apexearth/egrep --saveUse with Command Line
$ npm install @apexearth/egrep -gNode.js Usage
let egrep = require('@apexearth/egrep')
let stream = egrep({
pattern: /test[1-9]/,
files: [
'test_files/file1.txt',
'test_files/',
],
recursive: true,
})
stream.on('data', data => {
console.log(data)
})
stream.on('error', err => {
console.log(err)
})
stream.on('close', () => {
console.log('closed')
})Output:
{ file: 'test_files/file1.txt', line: 'aaaaaaatest4aaaaaaa' }Use with callback:
egrep({
pattern: /test[1-9]/,
files: [
'test_files/file1.txt',
'test_files/',
],
recursive: true,
objectMode: false,
}, (err, result) => {
if (err) console.log(err)
console.log(result)
})Output:
test_files/file1.txt:aaaaaaatest4aaaaaaaOptions
files: The files, folders, or globs to grep.pattern: The pattern to grep for.glob: Treat files option as a glob.recursive: Recursively grep through folders.ignoreCase: Perform case insensitive matching.excludes: Array of RegExp exclusions.objectMode: Setfalseto receive string data.fullBinaryMatches: Settrueto display the full binary match.hideBinaryMatches: Settrueto hide all binary matches.
Command Line Usage
Usage: node-egrep [options] <pattern> <file...>
Options:
-V, --version output the version number
-r, --recursive Walk through directories recursively.
-R, --recursive Walk through directories recursively.
-g, --glob Treat file args as globs.
-i, --ignore-case Perform case insensitive matching.
-f, --file <file> Read one or more newline separated patterns from file. Empty pattern lines match every input line.
--exec <cmd> Execute a command for each match with {1}=file {2}=line
-h, --help output usage informationExamples:
$ node-egrep 123 test_files/numbers
1234567890
$ node-egrep -r abc test_files
test_files/one/abc:abcdefg
test_files/one/two/letters:abc
$ node-egrep -g abc "test_files/**"
test_files/one/abc:abcdefg
test_files/one/two/letters:abcCompatibility
Node.js versions 8, 10, and 11.