Shell脚本分割文件成相同行数的文件
使用shell脚本将testfile.txt文件(共7800行)分割成13个文件,每个文件600行,文件名的前缀是SplitFile
脚本如下:
#!/bin/sh
linenum=`wc -l testfile.txt |awk '{print $1}'`
Num1=1
FileNum=1
while [ $Num1 -lt $linenum ]
do
Num2=`expr $Num1 + 599`
sed -n "${Num1}, ${Num2}p " testfile.txt > SplitFile$FileNum
Num1=`expr $Num2 + 1`
FileNum=`expr $FileNum + 1`
done
最后生成的文件是
SplitFile1
SplitFile10
SplitFile11
SplitFile12
SplitFile13
SplitFile2
SplitFile3
SplitFile4
SplitFile5
SplitFile6
SplitFile7
SplitFile8
SplitFile9
最后再核实一下每个文件的大小是否一致
相关推荐
tianhuak 2020-11-24
huha 2020-10-16
lianshaohua 2020-09-23
laisean 2020-11-11
zhangjie 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
CARBON 2020-10-20
彼岸随笔 2020-10-20
lianshaohua 2020-10-20
yutou0 2020-10-17
JohnYork 2020-10-16
xiaonamylove 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
ourtimes 2020-10-16