From mboxrd@z Thu Jan 1 00:00:00 1970 From: erik quanstrom Date: Sat, 8 May 2010 00:41:42 -0400 To: 9fans@9fans.net Message-ID: In-Reply-To: <4be4dd37.NDxcevbsQ+CfYFvN%yard-ape@telus.net> References: <4be4dd37.NDxcevbsQ+CfYFvN%yard-ape@telus.net> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: Re: [9fans] Binary File split Topicbox-Message-UUID: 1e3680ba-ead6-11e9-9d60-3106f5b1d025 On Fri May 7 23:42:15 EDT 2010, yard-ape@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-) } }