Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80665 views
1
#!/usr/bin/env node
2
var argv = require('optimist')
3
.usage('Count the lines in a file.\nUsage: $0')
4
.demand('f')
5
.alias('f', 'file')
6
.describe('f', 'Load a file')
7
.argv
8
;
9
10
var fs = require('fs');
11
var s = fs.createReadStream(argv.file);
12
13
var lines = 0;
14
s.on('data', function (buf) {
15
lines += buf.toString().match(/\n/g).length;
16
});
17
18
s.on('end', function () {
19
console.log(lines);
20
});
21
22