| | |
Parsing Problem
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 9
Reputation:
Solved Threads: 0
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.
'''
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.
0
#3 Nov 3rd, 2009
hi
I'm not sure if this will help you but here goes:
I'm not sure if this will help you but here goes:
Python Syntax (Toggle Plain Text)
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 >>>
![]() |
Similar Threads
- Basic parsing problem...Help plz (Perl)
- Problem in Unicode Parsing. (Java)
- Parsing Problem (Perl)
- parsing problem (Perl)
- Problem with Perl syntax highlighter (DaniWeb Community Feedback)
- Featured Blogs query.. (Geeks' Lounge)
Other Threads in the Python Forum
- Previous Thread: Pumpkin Weight Help
- Next Thread: Removing a substring from string
Views: 121 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Python
approximation array beginner book builtin change cipher clear client code color converter countpasswordentry cturtle curved def dictionary drive dynamic examples excel file float format ftp function gui homework import inches input java library line lines linux list lists loop microcontroller mouse mysqldb mysqlquery newb number numbers output parsing path plugin port prime program programming projects py2exe pygame pymailer pyqt python random recursion recursive redirect remote script scrolledtext search singleton socket sqlite ssh string strings strip subprocess sum syntax table terminal text textarea thread threading time tkinter tlapse tuple tutorial twoup ubuntu unicode urllib urllib2 variable vigenere wikipedia windows wxpython xlwt





