最近准备写个文件分割的工具, 跟同事交流后, 发现linux早已提供了这个命令,来一起看下:
taoge@localhost Desktop> ls
a.txt
taoge@localhost Desktop> cat a.txt
3576661317
3577352199
3577724088
3578367381
3578587869
3579287088
3581127558
3582079011
3582736026
3585019998
taoge@localhost Desktop> filename="a.txt"
taoge@localhost Desktop> rm test_* -f
taoge@localhost Desktop> total=`cat $filename | wc -l`
taoge@localhost Desktop> onefile=$(( $total / 3 + 1))
taoge@localhost Desktop> split -l $onefile $filename -d -a 4 "test_"
taoge@localhost Desktop>
taoge@localhost Desktop>
taoge@localhost Desktop> ls
a.txt test_0000 test_0001 test_0002
taoge@localhost Desktop> wc -l test*
4 test_0000
4 test_0001
2 test_0002
10 total
taoge@localhost Desktop>
注意, 如下命令我是批量赋值到linux命令终端的: