The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Please help me pick a machine Gnfanatic SUN Solaris 11 04-11-2006 11:06 AM
How to grep the exact name? csaha Shell Programming and Scripting 3 01-31-2006 08:47 AM
grep - exact wxornot UNIX for Dummies Questions & Answers 9 01-02-2006 11:03 AM
Echo-exact matthewwithanm Shell Programming and Scripting 1 08-16-2005 09:38 PM
what is the exact reason ? shamal High Level Programming 2 12-08-2001 10:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-21-2008
Registered User
 

Join Date: Aug 2005
Location: Bangalore
Posts: 200
Pick the exact value

Hi,

How do i pick a particular value from a group of lines using python.

for instance from the below sample. How do I pick Value=1 of OuterLines=1 and InnerLine=1
Quote:
OuterLines=1
InnerLine=1
Value=1
InnerLine=2
value=2
InnerLine=3
value=3
OuterLines=2
InnerLine=1
value=1
InnerLine=2
value=2
InnerLine=3
value=3
Reply With Quote
Forum Sponsor
  #2  
Old 01-21-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
show what you have next time.
Code:
#!/usr/bin/python
f=open("file")
for line in f:
    if line.startswith("OuterLines=1"):
        if f.next().startswith("InnerLine=1"):
            print f.next()
f.close()
Reply With Quote
  #3  
Old 01-22-2008
Registered User
 

Join Date: Aug 2005
Location: Bangalore
Posts: 200
But there could be multiple lines after the Innerline=1, In the below data i need all 6 value=1 lines

Quote:
OuterLines=1
InnerLine=1
Value=1
Value=1
Value=1
Value=1
Value=1
Value=1
InnerLine=2
value=2
InnerLine=3
value=3
OuterLines=2
InnerLine=1
value=1
InnerLine=2
value=2
InnerLine=3
value=3
Reply With Quote
  #4  
Old 01-22-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
#!/usr/bin/python
f=open("file")
for line in f:
    if line.startswith("OuterLines=1"):
        if f.next().startswith("InnerLine=1"):
            while 1:
                N=f.next().strip()
                if N.startswith("InnerLine=2"): 
                    break
                print N
f.close()
Reply With Quote
  #5  
Old 01-22-2008
Registered User
 

Join Date: Aug 2005
Location: Bangalore
Posts: 200
But i wouldnt be knowing the Innerline=2 value. i'll have the Outerline=1 and innerline=1
Reply With Quote
  #6  
Old 01-22-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by ahmedwaseem2000 View Post
But i wouldnt be knowing the Innerline=2 value. i'll have the Outerline=1 and innerline=1
then you make it break when the value is not "Value=1". otherwise, you have to provide a more concrete example of your sample data. I followed what is provided by you.
Reply With Quote
  #7  
Old 01-22-2008
Registered User
 

Join Date: Aug 2005
Location: Bangalore
Posts: 200
Below mentioned is the sample data. I would have the value of JS name( that is XXX of the first tag) and J name values ( that is X_NAME1 of the first tag). Using which i should find all the "C f" values

Thanks


Quote:
<JSF>
<JS name="XXX">
<J name="X_NAME1">
<C f="Val1" />
<C f="val2" />
</J>
<J name="Y_NAME1">
<C f="Val1" />
</J>
<J name="Z_NAME1">
<C f="Val1" />
</J>
</JS>
<JS name="YYY">
<J name="X_NAME1">
<C f="val1" />
</J>
<J name="Y_NAME1">
<C f="val1" />
</J>
</JS>
</JSF>
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0