Parsing Problem

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2009
Posts: 9
Reputation: krishna_sicsr is an unknown quantity at this point 
Solved Threads: 0
krishna_sicsr krishna_sicsr is offline Offline
Newbie Poster

Parsing Problem

 
0
  #1
Nov 3rd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 9
Reputation: krishna_sicsr is an unknown quantity at this point 
Solved Threads: 0
krishna_sicsr krishna_sicsr is offline Offline
Newbie Poster
 
0
  #2
Nov 3rd, 2009
Hi I have done this.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 243
Reputation: masterofpuppets is an unknown quantity at this point 
Solved Threads: 67
masterofpuppets's Avatar
masterofpuppets masterofpuppets is offline Offline
Posting Whiz in Training
 
0
  #3
Nov 3rd, 2009
hi
I'm not sure if this will help you but here goes:

  1. f = \
  2. '''
  3. Product: DECNET Node: ALETHA Address(es): 1.1
  4. Product: TCP/IP Node: aletha.ind.hp.com Address(es): 15.146.239.174
  5. '''
  6. lines = f.split('\n')
  7. i = 1
  8.  
  9. ###### To get the IP Address(es)
  10. adapter_config = True
  11. for line in lines:
  12. if adapter_config:
  13. # print line
  14. import re
  15. if ( re.match( "^Product: TCP/IP\s+", line ) ):
  16. line1 = re.split( "\s+", line )
  17. print line1[ 5 ]
  18.  
  19. >>>
  20. 15.146.239.174
  21. >>>
My site ->> http://8masterofpuppets8.webs.com/
"My belief is stronger than your doubt."
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 243
Reputation: masterofpuppets is an unknown quantity at this point 
Solved Threads: 67
masterofpuppets's Avatar
masterofpuppets masterofpuppets is offline Offline
Posting Whiz in Training
 
0
  #4
Nov 3rd, 2009
oh sorry I posted this already.
My site ->> http://8masterofpuppets8.webs.com/
"My belief is stronger than your doubt."
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 122 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC