Skip to content

Instantly share code, notes, and snippets.

@alanmquach
Last active August 29, 2015 14:19
Show Gist options
  • Save alanmquach/65b663f6a34200302519 to your computer and use it in GitHub Desktop.
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')
#!/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