Last active
January 1, 2016 07:19
-
-
Save luistung/8110723 to your computer and use it in GitHub Desktop.
按第一字段切分文件
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
#!/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