2013-04-25 9:05:03
#!/bin/bash if [ $# -ne 2 ]; then file=$1 if [ ! -f $file ]; then #TODO: test if $size is a valid integer filesize=`/bin/ls -l $file | awk '{print $5}'` let pieces=$filesize/$size i=0 echo "#!/bin/bash" >; merge
echo 'Usage: split file size(in bytes)'
exit
fi
size=$2
echo "$file doesn't exist"
exit
fi
echo filesize: $filesize
let remain=$filesize-$pieces*$size
if [ $remain -gt 0 ]; then
let pieces=$pieces+1
fi
echo pieces: $pieces
while [ $i -lt $pieces ];
do
echo split: $file.$i:
dd if=$file of=$file.$i bs=$size count=1 skip=$i
let i=$i+1
done
echo "i=0" >;>; merge
echo "while [ $i -lt $pieces ];" >;>; merge
echo "do" >;>; merge
echo " echo merge: $file.$i" >;>; merge
echo " if [ ! -f $file.$i ]; then" >;>; merge
echo " echo merge: $file.$i missed" >;>; merge
echo " rm -f $file.merged" >;>; merge
echo " exit" >;>; merge
echo " fi" >;>; merge
echo " dd if=$file.$i of=$file.merged bs=$size count=1 seek=$i" >;>; merge
echo " let i=$i+1" >;>; merge
echo "done" >;>; merge
chmod u+x merge'
One Response