标签:os ar for 文件 sp c linux line ad
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)
标签:os ar for 文件 sp c linux line ad
原文地址:http://www.cnblogs.com/charlie-badegg/p/3962690.html