Created
May 2, 2011 07:56
-
-
Save chaoxu/951286 to your computer and use it in GitHub Desktop.
Combine freetalk history files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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