Last active
April 11, 2017 06:06
-
-
Save ppeeou/59694b6d307d5ca90f2f6466ab94cec1 to your computer and use it in GitHub Desktop.
Nodejs File Read 정규식표현 적용
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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