Pages

Monday, May 26, 2014

Extract domain from URl

$ MYURL=http://test.example.com ; awk -F/ '{ print $3 }' <<< $MYURL | awk -F. '{ if ( $(NF-1) == "co" || $(NF-1) == "com" ) print $(NF-2)"."; print $(NF-1)"."$(NF); }'

Extracts domain and subdomain from given URl. See examples.




commandlinefu.com


by David Winterbottom (codeinthehole.com)






from All commands http://ift.tt/1jPMeuD

No comments:

Post a Comment