Skip to content

Instantly share code, notes, and snippets.

@luistung
Last active January 1, 2016 07:19
Show Gist options
  • Save luistung/8110723 to your computer and use it in GitHub Desktop.
Save luistung/8110723 to your computer and use it in GitHub Desktop.
按第一字段切分文件
#!/bin/env python
#usage argv[0] file_tobe_split target_dir
#按第一字段切分文件
import sys
src_file = sys.argv[1]
tgt_dir = sys.argv[2]
last_index = None
for line in open(src_file):
line = line.rstrip()
index = line.split('\t')[0]
if last_index is None or index <> last_index:
file = open(tgt_dir + '/' + index, 'w')
print >>file, line
last_index = index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment