You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
409 B

8 years ago
  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. var fs = require('fs');
  10. var s = fs.createReadStream(argv.file);
  11. var lines = 0;
  12. s.on('data', function (buf) {
  13. lines += buf.toString().match(/\n/g).length;
  14. });
  15. s.on('end', function () {
  16. console.log(lines);
  17. });