Created
April 1, 2016 12:04
-
-
Save yoava/579fe6953a22ca724ed3afd95929f389 to your computer and use it in GitHub Desktop.
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
// sort5 uses `sort -k3,3`, and process the response sent to stdout | |
////////////////////////////////////////////////////////////////////////////////////// | |
var fs = require('fs'), | |
util = require('util'), | |
spawn = require('child_process').spawn, | |
sort = spawn('sort', ['-k3,3', './input.txt']); | |
var start = Date.now(); | |
var writer = fs.createWriteStream('out5.txt'); | |
sort.stdout.on('data', function (data) { | |
// process data | |
data.toString() | |
.split('\n') | |
.map(line => line.split("\t")) | |
.forEach(record => writer.write(record.join('\t') + '\n')); | |
}); | |
sort.on('exit', function (code) { | |
if (code) { | |
// handle error | |
} | |
writer.end(); | |
var closetime = Date.now(); | |
console.log('Time. ', (closetime - start) / 1000, ' secs'); | |
}); | |
// optional | |
sort.stderr.on('data', function (data) { | |
// handle error... | |
console.log('stderr: ' + data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment