Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use split and cat to make segments and rejoin them UNIX
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.
    •    
  • Currently 2.86 / 5
  You rated: 1 / 5 (7 votes cast)
 
[35,281 views]  

Use split and cat to make segments and rejoin them | 15 comments | Create New Account
Click here to return to the 'Use split and cat to make segments and rejoin them' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use split and cat to make segments and rejoin them
Authored by: AaronAdams on Jan 31, '06 07:23:31AM

You could also create a segmented, compressed disk image that can be mounted with a double-click and can also be scripted:

http://www.aaronadams.net/index.php/2005/10/18/make_large_files_span_multiple_optical_d



[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: boredzo on Jan 31, '06 07:38:46AM

other way to use split:

cat MySegmentab MySegmentac MySegmentad >> MySegmentaa


[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: boredzo on Jan 31, '06 07:40:35AM

and by split, I meant cat.



[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: tirerim on Jan 31, '06 08:26:11AM
Or, if you have a bunch of segments and don't want to type them all out:

cat MySegment* >> MySegmentaa

The wildcard should expand in standard alphabetical order.

[ Reply to This | # ]

Use split and cat to make segments and rejoin them
Authored by: boredzo on Feb 01, '06 11:25:52PM

no; MySegment* would include MySegmentaa, so that when you appended all three to MySegmentaa, the contents of MySegmentaa would appear twice in the result.

and > (overwrite) would not work, because then there would be no MySegmentaa to read from.



[ Reply to This | # ]
Split&Concat
Authored by: vdanen on Jan 31, '06 07:41:48AM

You can also use Split&Concat to do the same thing:

http://www.xs4all.nl/~loekjehe/Split&Concat/

It's DonationWare and licensed under the GPL so anyone can use it. Very easy to use too.



[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: joebob on Jan 31, '06 08:24:25AM

Use jot in a for loop for an easier way to join segments. This is example is for four segments; replace 4 with the actual number of segments you have.

for x in `jot -c 4 a` ; do cat Mysegmenta$x >> Mysegmenta ; done



[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: Jwink3101 on Jan 31, '06 08:44:18AM

Is there a way to rejoin [and maybe split] in windows?



[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: jacobolus on Jan 31, '06 09:36:52AM

Just search google, there are a ton of shareware/freeware programs that do this. Alternately, you could install cygwin and use this hint.



[ Reply to This | # ]
HJSplit
Authored by: jguice on Jan 31, '06 01:41:58PM
I was always partial to HJSplit on Windows [Freeware]. And now they apparently have many versions for various operating systems.

http://www.freebyte.com/hjsplit/

[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: axis on Nov 22, '06 01:37:58PM

Sure is - Search for a program called hjsplit I think. I used to use it quite frequently back in my windows days.



[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: ocdinsomniac on Jan 31, '06 04:54:15PM

Hi. I've posted a script to automate this process on my blog. You can find it here:
http://systemsboy.blogspot.com/2006/01/scripts-part-3-split-and-rejoin-large.html

Hope this is useful for someone.

-systemsboy



[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: BMarsh on Jan 31, '06 05:12:54PM

other then Split&Concat (Shareware) that was already mentioned, there is also a freeware program that gives a GUI to the command-line tools:
MacHacha
http://www.versiontracker.com/dyn/moreinfo/macosx/18628
or developers website:
http://homepage.mac.com/julifos/soft/machacha/index.html
(MacHacha also handles a few other split & join formats)



[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: Nairda on May 18, '08 03:45:27PM
The correct wildcard-syntax would be:
cat MyFile* > MyFile
Joining all parts together to a new file.

[ Reply to This | # ]
Use split and cat to make segments and rejoin them
Authored by: mdwittenberg on Jan 29, '11 12:35:56PM
Additionally you can add the extension automatically by simply accounting for it in the terminal command:
cat MyFiles* > MyFiles.gz

[ Reply to This | # ]