Need simple algorithm for newbie
William Park
opengeometry at yahoo.ca
Tue Nov 5 16:11:26 EST 2002
Jason Tudisco <tudisco at sexmagnet.com> wrote:
> I have a list of domains... Some of the domain names in the list look
> like this:
>
> groups.goodle.com
>
> The information I want is just google.com. I need to know the best way
> to do this.. for .com .net .org only.. and to strip the rest of the
> garbage.. like in this case.. get rid of groups in groups.google.com
>
> I need to parse though a huge list so it has to be optimized algorithm
>
> No need to write complete code.. Just get me in the right direccion..
> Still learning python and I am not sure what would be the fastest way
> to go about it..
I assume you only want the last 2 fields. In that case,
1. Python:
a = 'groups.goodle.com'.split('.')
a[-2:]
2. Awk:
echo 'groups.goodle.com' | gawk -F '.' '{print $(NF-1) "." $NF}'
3. Shell:
a=groups.goodle.com
b=${a%.*.*}
echo ${a#$b.}
--
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
Linux solution for data management and processing.
1986 VW Jetta, 350000km :-))
More information about the Python-list
mailing list