f = \
'''
Product: DECNET Node: ALETHA Address(es): 1.1
Product: TCP/IP Node: aletha.ind.hp.com Address(es): 15.146.239.174
'''
lines = f.split('\n')
i = 1

###### To get the IP Address(es)
adapter_config = True
for line in lines:
if adapter_config:
# print line
import re
if (re.match("^Product:\s+",line)):
line1=re.split("\s+",line)
print line1[5]


I want to parse IP Address (15.146.239.174) from the above output, but in my script in line1[5] I am getting 1.1 and 15.146.239.174 both. How can I get only 15.146.239.174 thru my script.

hi
I'm not sure if this will help you but here goes:

f = \
'''
Product: DECNET Node: ALETHA Address(es): 1.1
Product: TCP/IP Node: aletha.ind.hp.com Address(es): 15.146.239.174
'''
lines = f.split('\n')
i = 1

###### To get the IP Address(es)
adapter_config = True
for line in lines:
    if adapter_config:
    # print line
        import re
        if ( re.match( "^Product: TCP/IP\s+", line ) ):
            line1 = re.split( "\s+", line )
            print line1[ 5 ]

>>> 
15.146.239.174
>>>
This question has already been answered. Start a new discussion instead.