Skip to content

Instantly share code, notes, and snippets.

@maluta
Created October 17, 2010 00:22
Show Gist options
  • Save maluta/630395 to your computer and use it in GitHub Desktop.
Save maluta/630395 to your computer and use it in GitHub Desktop.
split files with dd
#!/bin/sh
if [ $# -ne 2 ]
then
echo "./split.sh <number of files> <filename>"
exit
fi
size=`du $2 | awk '{ print $1 }'`
parts=`expr $size \/ $1`
parts=$[$parts+1] # "truncate"
echo $parts
echo $size
n="0"
i="1"
# split
while [ `expr $n + $parts` -lt $size ]
do
dd if=$2 of=pt-$i skip=$n bs=1K count=$parts
n=`expr $n + $parts`
i=$[$i+1]
done
dd if=$2 of=pt-$i skip=$n bs=1K
# merge
cp pt-1 out
n="0"
i=$[$i-1]
for ii in `seq 2 $i`
do
n=`expr $n + $parts`
dd if=pt-$ii of=out bs=1K seek=$n count=$parts
done
n=`expr $n + $parts`
i=$[$i+1]
dd if=pt-$i of=out bs=1K seek=$n
# verify the integrity
md5sum $2 out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment