[Tutor] Parse Problem [2]
fleet@teachout.org
fleet@teachout.org
Mon, 12 Aug 2002 14:57:49 -0400 (EDT)
I think I've got it licked. As I told Danny, I don't control the file
that I'm parsing so splitting on the quotes or including commas etc. is
not an option. Here's what I've done:
import time
import string
curtime=time.localtime(time.time())
curdate=time.strftime("%y%m%d",curtime)
log=open("log","r")
for rline in log.readlines():
line=string.split(rline," ")
if line[1]=="Matched":
line1=rline[19:-2] <-- #slicing the "unsplit" line
print "%s %s" % (line1, curdate) #that meets the criteria of the
line=string.split(rline,":") #'if' statement.
# note use of continuation below.
if line[1][1:-1] =="Missing action" or \
line[1]=="Invalid regexp" or \
line[1]=="Incomplete recipe":
line1=line[1][1:-1]
print "%s %s" % (line1, curdate)
- fleet -
PS: Danny, two minutes after I posted to you with the grep|cut|sed shell
command, I realized it was also including only the first word - and for
exactly the same reason.
On Mon, 12 Aug 2002 alan.gauld@bt.com wrote:
> > Given the strings 'xxxxx: xxxxx "xxx xxx"' and 'xxxxx: xxxxx
>
> > need to get everything within the quotes as xx[2].
>
> A quick guess - why not split on the quotes:
>
> string.split(str, '"') ?? Would that help?
>
> Alan g
>