Skip to content

Instantly share code, notes, and snippets.

@meling
Created May 20, 2015 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meling/912b2b905ce43fb42f5a to your computer and use it in GitHub Desktop.
Save meling/912b2b905ce43fb42f5a to your computer and use it in GitHub Desktop.
Example to extract with reg.exp.
import re
def ExtractPval(line):
# 2015-04-09 14:15:37,019 com6 INFO <=3.004882812 [CR][LF]
start = line.index('=')+1
stop = line.index('[')-1
return float(line[start:stop])
def main():
f=open('acudump1.txt','r')
data = {}
line = f.readline()
while line != '':
match = re.search('<=ips tic 2 acu/(ps.+?) value', line)
if match:
key = match.group(1)
nxtLine = f.readline()
value = ExtractPval(nxtLine)
if not data.has_key(key):
data[key]=[]
data[key].append(value)
line = f.readline()
print data
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment