![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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:
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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()
|
|
#3
|
|||
|
|||
|
But there could be multiple lines after the Innerline=1, In the below data i need all 6 value=1 lines
Quote:
|
|
#4
|
|||
|
|||
|
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()
|
|
#5
|
|||
|
|||
|
But i wouldnt be knowing the Innerline=2 value. i'll have the Outerline=1 and innerline=1
|
|
#6
|
|||
|
|||
|
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.
|
|
#7
|
|||
|
|||
|
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:
|
|||
| Google The UNIX and Linux Forums |