Skip to content

Instantly share code, notes, and snippets.

@xiaojay
Created May 30, 2013 04:35
Show Gist options
  • Save xiaojay/5675738 to your computer and use it in GitHub Desktop.
Save xiaojay/5675738 to your computer and use it in GitHub Desktop.
python script for masquerading squid log
#coding=utf-8
import sys, json
users = {}
uid = 0
fn = open(sys.argv[1])
while True:
line = fn.readline()
if not line:break
data = line.split()
user = data[7]
if user != '-':
u2 = users.get(user)
if not u2:
u2 = 'u%i'%uid
users[user] = u2
uid +=1
data[7] = u2
print ' '.join(data)
else:
print line[:-1]
open('users.txt', 'w').write(json.dumps(users))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment