-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupdate_merged.js
22 lines (19 loc) · 1.06 KB
/
update_merged.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// for each line in data/current.txt, if it is in data/identified.txt, print it instead of the line in data/current.txt
// if it is not in data/identified.txt, print the line in data/current.txt
// the usefulness of this is that it allows us to see possible context for unidentified hostnames, to maybe guess what they are
var fs = require('fs');
var current = fs.readFileSync('data/current.txt', 'utf8');
var identified = fs.readFileSync('data/identified.txt', 'utf8');
var currentLines = current.split('\n');
var identifiedLines = identified.split('\n');
var outputLines = [];
currentLines.forEach(function(line) {
// if any of the lines in identifiedLines starts with the line in currentLines, print the line in identifiedLines
var identifiedLine = identifiedLines.find(function(identifiedLine) {
return identifiedLine.startsWith(line);
});
outputLines.push(identifiedLine ? identifiedLine : line);
});
// write to data/merged.txt
fs.writeFileSync('data/merged.txt', outputLines.join('\n') + '\n');
console.log('wrote ' + outputLines.length + ' lines to data/merged.txt');