Created
March 7, 2012 21:05
-
-
Save corpix/1996250 to your computer and use it in GitHub Desktop.
Count lines with length >= than in a file
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
// node count-lines.js "somefile.txt" 12 | |
var fs = require('fs') | |
, length = process.argv.pop() | |
, filename = process.argv.pop() | |
, stream | |
, counter = 0; | |
stream = fs.createReadStream(filename); | |
stream.on('data', function(lines){ | |
if(!lines) | |
return; | |
lines = lines.toString().split('\n'); | |
for(var key in lines){ | |
if(lines[key].length >= length) | |
counter++; | |
} | |
delete lines; | |
}); | |
stream.on('end', function(){ | |
console.log('Lines with length %s -> %s', length, counter); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment