Created
October 3, 2014 14:43
-
-
Save lennym/3d4dd51150af1c8d4599 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
Usage: `node domains.js --file <inputfile.csv> | |
**/ | |
var fs = require('fs'); | |
var argh = require('argh').argv; | |
var _ = require('underscore'); | |
var input = argh.file; | |
fs.readFile(input, function (err, filedata) { | |
var rows = filedata.toString().split('\n'); | |
var domains = _.map(rows, function (e) { | |
return e.toLowerCase().split('@')[1]; | |
}); | |
domains = _.countBy(domains, _.identity); | |
domains = _.map(domains, function (val, key) { | |
return { domain: key, count: val}; | |
}); | |
domains = _.sortBy(domains, 'count'); | |
domains = _.last(domains, 30); | |
domains = _.pluck(domains, 'domain'); | |
console.log(domains); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment