Skip to content

Instantly share code, notes, and snippets.

@ilkermanap
Last active November 18, 2016 10:27
Show Gist options
  • Save ilkermanap/5c7fa6f71709474b205ed829d89fce2e to your computer and use it in GitHub Desktop.
Save ilkermanap/5c7fa6f71709474b205ed829d89fce2e to your computer and use it in GitHub Desktop.
for parsing headers with two lines.. I need this when parsing the output of iozone tests..
def split_with_location(line, separator=None):
temp = {}
t = line.strip()
finished = False
loc = 0
while len(t) > 0:
if separator is not None:
word = t.split(separator)[0]
else:
word = t.split()[0]
loc = line.find(word,loc)
temp[loc] = word
loc = loc + len(word)
t = line[loc:].strip()
return temp
def two_line_headers(line1,line2):
up = split_with_location(line1)
dn = split_with_location(line2)
newdn = dn
for loc2 in sorted(dn.keys()):
for loc1 in sorted(up.keys()):
if overlap(loc2, loc2 + len(dn[loc2]), loc1, loc1 + len(up[loc1])):
newdn[loc2] = up[loc1] +" "+ dn[loc2]
break
return newdn
def overlap(x1,x2, y1,y2):
res =False
if (x1 > y2) or (x2 < y1):
return False
return True
s1 = " random random bkwd record stride "
s2 = " kB reclen write rewrite read reread read write read rewrite read fwrite frewrite fread freread "
headers = two_line_headers(s1,s2)
for k,v in sorted(headers.items()):
print(k,v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment