Skip to content

Instantly share code, notes, and snippets.

@laughinghan
Created June 15, 2011 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laughinghan/1026576 to your computer and use it in GitHub Desktop.
Save laughinghan/1026576 to your computer and use it in GitHub Desktop.
merge.js
#!/usr/local/bin/node
var fs = require('fs');
var data = fs.readFileSync(process.argv[2]);
var target = fs.readFileSync(process.argv[3]);
var lines = (data+'').split('\n');
var rows = (target+'').split('\n');
var row = 0;
console.log(rows[0]);
for (var i = 0; i < lines.length; i += 1) {
var line = lines[i];
if (line === '') {
row += 1;
console.log(rows[row]);
continue;
}
if (line.split('\t')[1].split(' ').slice(2).length && line.split('\t')[2] === 'NA') {
line = line.split('\t');
line = line[0]+'\t'+line[1].split(' ').slice(0,2).join(' ')+'\t'+line[1].split(' ').slice(2).join(' ')+'\t'+line.slice(3).join('\t');
}
if (line.split('\t')[3].slice(0,1) !== '$') throw 'oh noes';
// if (rows[row] === undefined) {console.log(row, rows[row], i, line);return}
if (rows[row].split('\t').slice(1,3).join('\t').toUpperCase() !== line.split('\t').slice(0,2).join('\t')) {
row += 1;
console.log(rows[row]);
}
line = line.split('\t');
console.log('\t'+line[0]+'\t'+line[1]+'\t\''+line[2]+'\t'+line.slice(3).join('\t'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment