MacOS X and split

Split, on Mac OS X, doesn’t have the -d option to number files. This is a right royal pain when you are splitting up a dd image as I couldn’t figure out how to get either XWays Forensics or EnCase to accept the split image when suffixed with aaa, aab, aac etc. First time out of the gate I just paid a child to sit and re-number the lot for me ( which cost me £5 – but saved my sanity ), but for future reference and to save my financial status here is a (albeit long) one liner for the command line that will take any three letter suffixed filename & change it to the corresponding numerical value. (There are probably cleaner ways of doing this – feel free to let me know and I’ll be happy to update them here).

ls test.dd.* | awk 'BEGIN {FS="\\."}{print $3 ":" $0}' | 
awk -v FS="" '{ convert="abcdefghijklmnopqrstuvwxyz" } { first=index(convert,$1); 
second=index(convert,$2); third=index(convert,$3); 
printf "test.dd.%03d:", (third + (26 * ( second - 1 )) + ( 676 * ( first - 1 ))); print $0 }' | 
awk -v FS=":" '{print$3 " " $1}' | xargs -n 2 mv

Note that this has the output filename hard coded (test.dd.000). 

So this takes all the files, test.dd.aab, test.dd.aac etc. and converts them to test.dd.001, test.dd.002, test.dd.003. So, this will work for any number of files up-to and including zzz which is 17,576 – but extending it further wouldn’t be a particularly challenging task…

Tagged , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: