-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrep.js
More file actions
executable file
·32 lines (28 loc) · 738 Bytes
/
Copy pathgrep.js
File metadata and controls
executable file
·32 lines (28 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env babel-node
require('./helper')
const fs = require('fs').promise
const args = require('yargs').argv
const path = require('path')
async function findInFile(filePath) {
let content = fs.readFile(filePath, 'utf-8')
content = await content
const lines = content.split('\n')
for (const line of lines) {
if (line.indexOf(args._[0]) !== -1) {
console.log(line)
}
}
}
async function grep() {
if (args._[0] && args._[1]) {
let files = fs.readdir(__dirname)
files = await files
for (const file of files) {
if (file.match(args._[1])) {
console.log('Search for "' + args._[0] + '" in ' + file + ':')
await findInFile(path.join(__dirname, file))
}
}
}
}
grep()