import os
import sys
import subprocess
if len(sys.argv)<3 :
print ‘usage: filenum filename‘
file_num = sys.argv[1]
file_name = sys.argv[2]
p = subprocess.Popen([‘wc‘,‘-l‘,file_name],stdout=subprocess.PIPE)
sum_num = p.stdout.readline().split(‘ ‘)[0]
print sum_num
split_num = int(sum_num)/int(file_num)
os.system(‘cp ‘ + file_name + ‘ ‘ +file_name + ‘.backup‘)
for i in range(1,int(file_num)):
os.system(‘head -‘ + str(split_num) + ‘ ‘+ file_name + ‘>‘ + file_name + ‘_split_‘ + str(i))
os.system(‘sed \‘1,‘ + str(split_num) + ‘d\‘ ‘ + file_name + ‘>‘ + file_name + ‘.copy‘)
os.system(‘mv ‘ + file_name + ‘.copy ‘ + file_name)
os.system(‘mv ‘ + file_name + ‘ ‘ + file_name + ‘_split_‘ + file_num)
时间: 2024-10-14 05:06:27