Monday, 26 August 2013

Find strings after search in txt file

Find strings after search in txt file

I wondering if sombody could help me withth e following resolve the
following code:
I have a text-file called report.txt with following content (everything is
the same line):
Printed: 2013-07-12 05:09 PM QC Product: PROT2 CON Level: Level 3
Priority: QC Method RF Result 174 IU/mL Lot Number: 3BQH01 Sample ID:
3BQH01 Instrument ID: DV330681 QC Range 158.0 - 236.0 Comment Completed:
2013-07-12 17:09:14 Comment: Trigger: Manual Trigger Operator C160487AUR
Time of Run 2013-07-12 17:09:14 Reagent 13049MA
Now need to retrieve following information ( only the values after the : )
QC Product: PROT2 CON
Level: Level 3
Sample ID: 3BQH01
I was trying the following code:
with open ('report.txt', 'r') as inF:
for line in inF:
if 'Sample ID:' in line:
SID = line.split(':')[1].strip()
if 'Level:' in line:
LEV = line.split(':')[1].strip()
if 'QC Product:' in line:
QCP = line.split(':')[1].strip()
does anybody has an idea or an other solution?
Thanks a lot for all your efforts and help,
Kindly regards Koen

No comments:

Post a Comment