Last active
August 29, 2015 14:19
-
-
Save alanmquach/65b663f6a34200302519 to your computer and use it in GitHub Desktop.
Find/count unique lines (i.e. 'cat filewithduplicates.log | sort | uniq -c | sort -rn')
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
#!/usr/bin/env node | |
// $ cat filewithduplicates.log | uniq.js | sort -rn | cut -f 2- | |
var uniq = {}; | |
require('readline').createInterface({ | |
input: process.stdin, | |
terminal: false | |
}).on('line', function(line){ | |
uniq[line] = ++uniq[line] || 1; | |
}).on('close', function () { | |
Object.keys(uniq).forEach(function (key) { | |
console.log(uniq[key] + '\t' + key); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment