Skip to content

Instantly share code, notes, and snippets.

@thalweg
Created April 29, 2011 20:45
Show Gist options
  • Save thalweg/949012 to your computer and use it in GitHub Desktop.
Save thalweg/949012 to your computer and use it in GitHub Desktop.
Isolates the second- and top-level domain from the rest
#!/usr/bin/env awk -f
# returns "google.com" when called on "www.google.com"
# returns "google.com" when called on "foo.bar.zot.www.google.com"
BEGIN {
string=ARGV[1];
search=".";
n=split(string,array,search);
printf("%s%s%s\n",array[n-1],search,array[n]);
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment