some sed help needed

I have file with following contents;

127.0.0.1 www.google.com
127.3.3.1 www.cisco.com
127.3.5.1 www.msnbc.com

I want output as

127.0.0.1 www.google.com      google.com
127.3.3.1 www.cisco.com       cisco.com
127.3.5.1 www.msnbc.com       msnbc.com 

I tried

sed 's/www.//g' filename

and was able to remove www part i am not getting the end results...

how to fix it ?

In what way does it not do what you want?

i needed hostname with www and without www along with their ip in the same line as

127.0.0.1 www.google.com      google.com
127.3.3.1 www.cisco.com       cisco.com
127.3.5.1 www.msnbc.com       msnbc.com

Try something like :

sed "s#\([[:alnum:]]\{1,50\}\.com\)#& \1#g"  inputfile
sed 's/www\.\(.*\)/&\t\1/' file

( & in the replacement string represents the text that matched the entire regex, \1 is the text that matched the first \(...\) expression)

Thanks a lot... now i got it...

you are matching www. and the rest for back reference and then printing backreferenced one and original one...

am i correct ?

hmm

cool..
thanks a lot