Created
April 29, 2011 20:45
-
-
Save thalweg/949012 to your computer and use it in GitHub Desktop.
Isolates the second- and top-level domain from the rest
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
| #!/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