Tyler Scott | 384f37a | 2016-05-05 16:09:05 -0600 | [diff] [blame] | 1 | "use strict"; |
| 2 | const fs = require('fs'); |
| 3 | |
| 4 | const regex = /^Original File Name: ([\w\d-]+\.nc)\s*^NDN Name: (\/(?:[\w\d-]+\/)*)/gm; |
| 5 | |
| 6 | fs.readFile('sample_output', 'utf8',function(err, data){ |
| 7 | |
| 8 | if (err){ |
| 9 | return console.error(err); |
| 10 | } |
| 11 | |
| 12 | var output = {}; |
| 13 | for (let match = regex.exec(data); match; match = regex.exec(data)){ |
| 14 | if (output[match[2]]){ |
| 15 | console.log("Duplicate found for:", match[2], "|", output[match[2]], "|", match[1]); |
| 16 | continue; |
| 17 | } |
| 18 | output[match[2]] = match[1]; |
| 19 | } |
| 20 | |
| 21 | console.log("Found", Object.keys(output).length, "conversions."); |
| 22 | |
| 23 | fs.writeFile('conversions.json', JSON.stringify(output), function(err){ |
| 24 | if (err){ |
| 25 | return console.error(err); |
| 26 | } |
| 27 | }); |
| 28 | |
| 29 | }); |
| 30 | |