Skip to content

Instantly share code, notes, and snippets.

@brianfryer
Created September 23, 2013 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianfryer/6678569 to your computer and use it in GitHub Desktop.
Save brianfryer/6678569 to your computer and use it in GitHub Desktop.
This script is capable of parsing a snapnames text file to create a new text file that contains a list of domain names 6 characters in length or less.
// Get access to the file system
fs = require('fs');
// Grab the text file
var lines = fs.readFileSync('./snapnames.txt', 'utf8')
.replace(/([^\dA-z\.\-])+(\s+\S+\s+)/g, ',') // trim the file
.split(','), // make it into an array
domains = [];
// Parse each item in the array
for (i = 0; i < lines.length; i++) {
// Exclude the TLD
var domainName = lines[i].split('.');
// If the domain's length is less than 6 characters...
if (domainName[0].length <= 6) {
// ...add it to the `domains` array
domains.push(lines[i]);
}
}
// Return a list of domain names that are less than 6 characters long
fs.writeFileSync('./snapnames-lessthan5.txt', domains.join('\n'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment