grepcount.js 472 B

123456789101112131415161718
  1. var temp = require('../lib/temp'),
  2. fs = require('fs'),
  3. util = require('util'),
  4. exec = require('child_process').exec;
  5. var myData = "foo\nbar\nfoo\nbaz";
  6. temp.open('myprefix', function(err, info) {
  7. if (err) throw err;
  8. fs.write(info.fd, myData);
  9. fs.close(info.fd, function(err) {
  10. if (err) throw err;
  11. exec("grep foo '" + info.path + "' | wc -l", function(err, stdout) {
  12. if (err) throw err;
  13. util.puts(stdout.trim());
  14. });
  15. });
  16. });