On Fri May  7 23:42:15 EDT 2010, yard-...@telus.net wrote:
> How might I split a file into pieces specified by size?
> 
> split(1) lets me specify lines and regex contexts as delimiters, but what if 
> I want a 40MB file split up into 1.44MB chunks, say?

in retrospect, this would be better in c.  sometimes
it's just a challenge to use a screwdriver like a pry bar.

- erik

---

#!/bin/rc
if(~ $#* 0 1){
        echo usage: bsplit sz file >[1=2]
        exit usage
}
ch=$1
shift
for(i){
        sz=`{ls -ld $i | awk '{print $6}'}
        j = `{awk 'BEGIN{
                sz = ENVIRON["sz"]
                ch = ENVIRON["ch"]
                
                digits = log((sz + ch - 1)/ch)/log(16);
                o = 0;
                for(i = 0;; i++){
                        if(o + ch >= sz)
                                break;
                        print i
                        printf "%.*x\n", digits, i
                        o += ch
                }
                if(o < sz){
                        print i
                        printf "%.*x\n", digits, i
                }

                }'
        }
        while(! ~ $#j 0){
                dd -if $i -of $i^$j(2) -iseek $j(1) -count 1 -bs $ch >[2=]
                j = $j(3-)
        }
}

Reply via email to