Skip to content

Instantly share code, notes, and snippets.

@chaoxu
Created May 2, 2011 07:56
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 chaoxu/951286 to your computer and use it in GitHub Desktop.
Save chaoxu/951286 to your computer and use it in GitHub Desktop.
Combine freetalk history files
#!/usr/bin/python2
#usage: scriptname file1 file2 ...
import sys
import re
def toarray(a):
entrystart = re.compile('[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} \[[^\s]*@[^\s]*\]')
a2 = []
for line in a:
match = entrystart.match(line)
if match is not None:
a2.append(line)
else :
s = a2.pop()
s += line
a2.append(s)
return a2
def filetoarray(s):
f = open(s,'r')
return toarray(f.readlines())
a = []
a = map(filetoarray, sys.argv[1:])
a = [item for sublist in a for item in sublist]
a = list(set(a))
a.sort()
map(sys.stdout.write, a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment