Skip to content

Instantly share code, notes, and snippets.

@ppeeou
Last active April 11, 2017 06:06
Show Gist options
  • Save ppeeou/59694b6d307d5ca90f2f6466ab94cec1 to your computer and use it in GitHub Desktop.
Save ppeeou/59694b6d307d5ca90f2f6466ab94cec1 to your computer and use it in GitHub Desktop.
Nodejs File Read 정규식표현 적용
var fs = require('fs');
var es = require('event-stream');
var url = './data/smartIndoorAPI/';
var REGEX = /branchEventList/g;
fs.readdir(url, function (err, files) {
if (err) throw err;
files.forEach(function (file) {
var cnt = 0;
var s = fs.createReadStream(url + file)
.pipe(es.split())
.pipe(es.mapSync(function (line) {
if (line.match(REGEX)) cnt++;
})
.on('error', function () {
console.log('Error while reading file :', file);
})
.on('end', function () {
console.log('Read entire file : ', file, cnt)
})
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment