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=1
Newfile=$Filename\.bak
while [ $i -le $Subfilenum ]
do
Subfilename=$Filename$i
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!" 用这两个脚本完成对file的分割、合并: [root]# ./ddf.sh file
The file size is 116616 Byte
Plese enter the subfile size(KB):
60
file will be divided into 2
file1
记录了60+0 的读入
记录了60+0 的写出
61440字节(61 kB)已复制,0.0352612 秒,1.7 MB/秒
file2
记录了53+1 的读入
记录了53+1 的写出
55176字节(55 kB)已复制,0.0316272 秒,1.7 MB/秒
file has been divided into 2
Done !
[root]# ls
caf.sh ddf.sh file file1 file2
[root]# ./caf.sh
Please enter file name:
file
Please enter the number of subfiles:
2
file1 done!
file2 done!
Subfiles be merged into file.bak
Success!
[root]# ls
caf.sh ddf.sh file file1 file2 file.bak