10

I've split a large file with the split command from a Terminal and copied it from a USB-stick to my MacBook.

This results in couple of files named 'xaa', 'xab', 'xac'.

How do I merge them together again from within a Terminal?

13
cat xaa > newfile
cat xab >> newfile
cat xac >> newfile

Basically using a single '>' operand send the output to a new file. using a double '>>' operand makes it append the contents to the end of an existing file (and also out of interest create it if it does not already exist.

If all your files are definitely in a neat alphabetical order, then you could use:

cat x* > newfile

or

cat xaa xab xac > newfile

in case the filenames aren't in alphabetical order.

  • 1
    You can also do cat xaa xab xac > newfile – binarybob Mar 13 '12 at 19:57
  • but of course, this sounds logical! :-) thanks! – Sander Versluys Mar 13 '12 at 20:01
  • It is the mac way after all. – bmike Mar 13 '12 at 23:20
  • 4
    @bmike More like the Unix way, am I right?! :) – Mathias Bynens Mar 26 '12 at 6:56
  • I split a file in Ubuntu 16, then concatenated it in OS X, to an NTFS drive using Paragon's driver, and the end result file was different. (I checked by running sha256sum filename on Ubuntu and openssl sha -sha256 filename on OS X.) When I concatenated it to an HTFS+ drive the concatenated file was correct. – Chris Oct 20 '17 at 11:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .