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.

29 lines
635 B

7 years ago
  1. #!/usr/bin/env node
  2. var argv = require('optimist')
  3. .usage('Count the lines in a file.\nUsage: $0')
  4. .options({
  5. file : {
  6. demand : true,
  7. alias : 'f',
  8. description : 'Load a file'
  9. },
  10. base : {
  11. alias : 'b',
  12. description : 'Numeric base to use for output',
  13. default : 10,
  14. },
  15. })
  16. .argv
  17. ;
  18. var fs = require('fs');
  19. var s = fs.createReadStream(argv.file);
  20. var lines = 0;
  21. s.on('data', function (buf) {
  22. lines += buf.toString().match(/\n/g).length;
  23. });
  24. s.on('end', function () {
  25. console.log(lines.toString(argv.base));
  26. });