-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Halliday
committed
May 15, 2011
1 parent
4166bbf
commit 4ca06b8
Showing
2 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env node | ||
var argv = require('optimist') | ||
.usage('Count the lines in a file.\nUsage: $0') | ||
.demand('f') | ||
.alias('f', 'file') | ||
.describe('f', 'Load a file') | ||
.argv | ||
; | ||
|
||
var fs = require('fs'); | ||
var s = fs.createReadStream(argv.file); | ||
|
||
var lines = 0; | ||
s.on('data', function (buf) { | ||
lines += buf.toString().match(/\n/g).length; | ||
}); | ||
|
||
s.on('end', function () { | ||
console.log(lines); | ||
}); |