忘了從哪摘來的了,作個記錄。對了,已改爲對ts文件合併code
#caf.sh:合併文件,須要合併的文件要放在一個文件夾裏 # 文件名分爲兩個部分,第一部分都相同,第二部分必須是從1開始的連續數字,例如file1,file2,file3 # 合併後的文件名爲file.bak #!/bin/sh #輸入文件名的第一部分 echo "Please enter file name:" read Filename if [ -z $Filename ];then echo "Error:The file name can not be empty" exit fi #輸入待合併文件的個數 echo "Please enter the number of subfiles:" read Subfilenum if [ -z $Subfilenum ];then echo "Error:The number of subfiles can not be empty" exit fi echo $Subfilenum | grep '^[0-9]\+$' > /dev/null if [ $? -ne 0 ];then echo "Error:Input must be a number" exit fi if [ $Subfilenum -eq 0 ];then echo "Error:The number of subfiles can not be zero" exit fi #合併文件 i=0 Newfile=$Filename\.ts while [ $i -le $Subfilenum ] do Subfilename=$Filename$i\.ts if [ -e $Subfilename ];then echo "$Subfilename done!" cat $Subfilename >> $Newfile i=`expr $i + 1` else echo "Error:$Subfilename does not exist" rm -rf $Newfile exit fi done echo "Subfiles be merged into $Newfile" echo "Success!"