Skip to content

Instantly share code, notes, and snippets.

@sora
Created June 3, 2011 17:53
Show Gist options
  • Save sora/1006787 to your computer and use it in GitHub Desktop.
Save sora/1006787 to your computer and use it in GitHub Desktop.
import os, sys
cnt = 0
for file in sys.argv[1:]:
for line in open(file, 'r'):
if cnt % 1000 == 0:
print cnt
o1 = o2 = o3 = o4 = str()
ipaddr = line[:-1]
o1, o2, o3, o4 = ipaddr.split('.')
if not os.access(o1, os.F_OK):
os.mkdir(o1)
if not os.access(o1+'/'+o2, os.F_OK):
os.mkdir(o1+'/'+o2)
if os.path.isfile(o1+'/'+o2+'/'+o3):
wf = open(o1+'/'+o2+'/'+o3, 'a')
else:
wf = open(o1+'/'+o2+'/'+o3, 'w')
wf.write(line)
wf.close()
cnt = cnt + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment