Use split and cat to make segments and rejoin them

Jan 31, '06 05:35:00AM

Contributed by: Anonymous

I have been trying to fit large compressed archives onto standard CD and DVD media. I have seen a few examples here on how to do this, so by goofing around, I found another method. I used split -b to chop up the files to the desired size, and then cat to put them together again.

First, take the files you want to split and gzip them (I won't explain that part, as it is so easy). Then with the resulting .gz file, do the following:

split -b 5m "YourGzippedFile.gz" SegmentFileName
The -b option will let you specify the size (use k for Kilobytes and m for Megabytes) and the SegmentFileName is the name of the splits that will be created, with aa, ab, ac, etc. appended after SegmentFileName until the file is completely split up. So say you split a file that was 20MB into four 5MB chunks (just an example). To reassemble them:
cat MySegmentab >> MySegmentaa
cat MySegmentac >> MySegmentaa
cat MySegmentad >> MySegmentaa
This will take each segment, starting with the second, and join it to the first (head) of the segment. Your file will be back together. Then just add .gz to its name and then gunzip it.

I tried this with a regular .zip file from a PC, and Stuffit Expander uncompressed the pieces after I split and rejoined them fine, and I also did this to a 50MB AIFF that I gzipped first, then put it back together and it played fine.

This could be scriptable, but I haven't gotten that far yet. The downside to this method is that it is not automatic, so a script would be helpful. It is also not necessarily apparent as to what the files are, so you would need to make sure there is some description in the title that is obvious (Part 1 of x) or something like that. Comments and especially potential pitfalls to this method are encouraged.

Comments (15)

Mac OS X Hints