Bill Randle wrote:
On Sat, 2008-04-26 at 11:17 -0700, Marc Perkel wrote:
Trying to do something that should be simple. Using sed to remove the first part of a hostname but not working. I want:

abc.def.com to become def.com

I tried a lot of variations of the following but it's either greedy or does nothing.

sed -e 's/^.*?[.]//'

Here are two options:

1) sed -e 's/^[^.]*\.//'
   It has a limitation that only the first host part is removed. I.e.:
   abc.def.com becomes def.com and xyz.abc.def.com becomes abc.def.com

2) sed -e 's/^.*\.\([^.]*\.[^.]*\)/\1/'
   This effectively strips out everything prior to the last portion
   before the last period. In essence, it reduces to the domain name.
   xyz.abc.def.com becomes def.com.


        -Bill
Hmm.. Might want to consider adding something to check to see if the part after the last period is only two characters long. I.E. www.domain.com.uk or great.spammer.com.ru


Reply via email to