Strip subdomains from domains list

Hello,

I'm trying to strip all the subdomains from a domains list.

Let's say the list is:

----------

admin.searchhippo.com
www.advertise.about.com.br
----------

I need to get

-----------

searchhippo.com
about.com.br
------------

One way:

awk -F\. '{print $(NF-1) FS $NF}' file

Thanks, this is almost good.

The problem is that it discards Country specific domains like
"bol.com.br" for example.

Then you need tell us in which way you need keep three sections in a domain name.

#removed#

According to the ISO standard:

Thus, you could assume that any domain ending in a two character code should print the last two subdomain names in addition to the top level domain:

# assume url is first field; change if needed
awk '
        {
                gsub( "^.*://", "", $1 );      # ditch the http://  ftp:// etc
                n = split( $1, a, "." );
                if( length( a[n] ) == 2 )       # assuming all two character top level domains are country codes
                        printf( "%s.%s.%s\n", a[n-2], a[n-1], a[n] );
                else
                        printf( "%s.%s\n",  a[n-1], a[n] );
        }
' list-file-name

This also takes into account that

http://foo.com

should not print anything before the double slants. Caution may need to be exercised as some countries have licensed the use of their top level domain name (e.g. .tv and .fm).

#!/bin/bash
exec 6<"myfile"
while read -r LINE<&6
do
   LINE=${LINE/www./}
   IFS="."
   LINE=(${LINE/http:\/\/})
   want="${LINE[@]:1}"
   echo "${want// /.}"
done
exec 6<&-