regular expressions

C

chaaana

hi..
im parsing the text file containing the details of the testcases
failed.From the file i wanted to obtain only the testcase names and
enter them in the excel sheet.

the pattern of the text file is:

FILE : NW_PTH_TFG6_SCEN_4_2_FIFO.c, LINE : 240 TEST FAIL to get entire:
32768 bytes
NW_PTH_TFG6_SCEN_4_2_FIFO.c 340 DATA NOT MATCHING, TEST FAIL
TEST FAIL SYSCALL_TEST_SCEN_4_1_ALL.c at line 355
FILE:US_TFG7_SCEN_4_1.c,LINE:189, Server side TEST FAIL
FAIL BREW_SCEN_4_1.c 219: can't mount
FAIL BREW_SCEN_4_1.c 121: can't umount
<< BREW_SCEN_4_1.c TEST FAIL errno:No such file or directory >>
<< BREW_SCEN_4_1.c TEST FAIL >> error:Invalid argument

i used the ' re module' and its function partition,but im facing
problem in obtaining only the testcase names..
if anyone know the answer please help me..
Thanks for ur help.
 
T

Terry Reedy

hi..
im parsing the text file containing the details of the testcases
failed.From the file i wanted to obtain only the testcase names and
enter them in the excel sheet.

the pattern of the text file is:

FILE : NW_PTH_TFG6_SCEN_4_2_FIFO.c, LINE : 240 TEST FAIL to get entire:
32768 bytes
NW_PTH_TFG6_SCEN_4_2_FIFO.c 340 DATA NOT MATCHING, TEST FAIL
TEST FAIL SYSCALL_TEST_SCEN_4_1_ALL.c at line 355
FILE:US_TFG7_SCEN_4_1.c,LINE:189, Server side TEST FAIL
FAIL BREW_SCEN_4_1.c 219: can't mount
FAIL BREW_SCEN_4_1.c 121: can't umount
<< BREW_SCEN_4_1.c TEST FAIL errno:No such file or directory>>
<< BREW_SCEN_4_1.c TEST FAIL>> error:Invalid argument

I do not see any consistent pattern in the above lines.
What output do you see from filtering them?
i used the ' re module' and its function partition,but im facing
problem in obtaining only the testcase names..

If I could not write a satisfactory re, I would be tempted to write
explicit code to process the lines, possibly defining appropriate search
states.

Terry Jan Reedy
 
T

Tim Chase

I do not see any consistent pattern in the above lines.
What output do you see from filtering them?

My guess is that it's the "FILE:...LINE:..." line(s) that the OP
is interested in, in which case one could do something like

r = re.compile(r'^FILE\s*:\s*(.*?),\s*LINE\s*:\s*(\d+)')
for line in file('input.txt'):
m = r.match(line)
if m:
print m.group(1), m.group(2)

Alternatively, if you're in the regexp-avoiding camp, you might
be able to get away with

LINE_BIT = ', LINE : '
for line in file('input.txt'):
if line.startswith('FILE :') and LINE_BIT in line:
leader, _ = line.split(LINE_BIT, 1)
_, fname = leader.split(":", 1)
fname = fname.strip()
print repr(fname)

but that relies on the LINE_BIT remaining constant (the
"LINE:189" doesn't have spaces where the first "LINE : 240" does
have extra spaces; and the same with the extra spaces around the
"FILE" portion).

-tkc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top