parsing a text file in python, c++, given specific format -


i have file in following format; parse in pyhton , c++ , extract number after impvarno: there lots of line in format.

sample.txt

start: abc pqr (ff_ggggg_confirm_tr):tc:20222,seqnum:86,impvarno:1000000008234436,id:12,oneid:66454,a/c:1,impvalue:905,impvar:25,actualvalue:905,actualvar:25,abc pqr xyz impquantity:0,pgb ncr yepp start: abc pqr (ff_ggggg_confirm_tr):tc:20222,seqnum:86,impvarno:1000000008234436,id:12,oneid:66454,a/c:1,impvalue:905,impvar:25,actualvalue:905,actualvar:25,abc pqr xyz impquantity:0,pgb ncr yepp start: abc pqr (ff_ggggg_confirm_tr):tc:20222,seqnum:86,impvarno:1000000008234436,id:12,oneid:66454,a/c:1,impvalue:905,impvar:25,actualvalue:905,actualvar:25,abc pqr xyz impquantity:0,pgb ncr yepp start: abc pqr (ff_ggggg_confirm_tr):tc:20222,seqnum:86,impvarno:1000000008234436,id:12,oneid:66454,a/c:1,impvalue:905,impvar:25,actualvalue:905,actualvar:25,abc pqr xyz impquantity:0,pgb ncr yepp 

so wrote following code:

#!/usr/bin/env python  import sys import re  hand = open('newlogfile.txt') line in hand:     r = re.compile("exorderno:(\d+),")      print r  

import re  open('newlogfile.txt') f:     r = re.compile("impvarno:(\d+),")     line in f:         inp = r.findall(line)         if inp:             print(float(inp[0]))  1000000008234436 1000000008234436 1000000008234436 1000000008234436 

if line starts same thing:

   import re      open('newlogfile.txt') f:         r = re.compile("impvarno:(\d+),")         line in f:             if line.startswith("(ff_ggggg_confirm_tr)"):                 print(r.findall(line)) 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -