标签:
1 #!/bin/bash 2 #大文件按行数分离成若干小文件脚本 3 4 con_data=‘db2 connect to db_edp‘ 5 con_time=‘db2 "values current timestamp"‘ 6 con_reset=‘db2 connect reset‘ 7 #将要分离的文件名写到此处,其它地方不要改动 8 clear_file=pdm_20160512.txt 9 10 echo $con_data > lianjie.txt 11 echo $con_time >> lianjie.txt 12 13 echo "添加连接数据库命令到分离文件中......" 14 awk ‘1;NR%40==0{system("cat lianjie.txt")}‘ $clear_file > $clear_file.bak 15 sed -i "1i $con_data" $clear_file.bak 16 sed -i "2i $con_time" $clear_file.bak 17 18 echo "开始分离文件......" 19 split -l 42 -d -a 3 $clear_file.bak del_ && ls| grep del_ | xargs -n1 -i mv {} {}.sh 20 21 echo "添加结尾时间戳到分离后的小文件中......" 22 for file in `ls|grep del_`;do 23 echo $con_time >> $file 24 echo $con_reset >> $file 25 done 26 27 echo "压缩分离后的小文件......" 28 tar cf $clear_file.tar del_* 29 30 echo "删除生成的文件......" 31 rm -f del_* lianjie.txt $clear_file.bak 32 33 echo "执行完成"
标签:
原文地址:http://www.cnblogs.com/miaoxg/p/5841496.html