I have 16 bz2 files of bz2 format: split.csv.0.bz2 split.csv.1.bz2 split.csv.2.bz2 ....

I believe this is a compressed csv file, but what makes me confused all day today is that it's splitted by 16 diff files.

I tried to decompress them all at once, but it's returning split.csv.0 split.csv.1 split.csv.2 .... 16 different files those are saying its file format is digit (format: 0, 1, 2....)

How should I work with these bz2 files to make it as a original csv file? I'm using Mac.

  • What are you using to decompress & how? By default, dropping the first in the series to any decompression app that can handle bz2 will find all the files in sequence & decompress to a single file. The built-in Archive Utility can handle bz2, so double-clicking the first file should be sufficient. – Tetsujin Aug 29 '20 at 8:19
  • @Tetsujin AFAIK bzip2 format has nothing to do with splitting. You can split a compressed file like any other file; then some applications may be smart enough to detect this and concatenate before decompressing. But here it's possible the original file was split before compressing each part on its own. Each compressed file is therefore complete and standalone. It's in the gist of *nix there are separate archivers (tar, pax), compressors (bzip2, gzip), split+cat, encryption tools; and one can use them in any sequence. To revert one needs to work backwards, the order matters. – Kamil Maciorowski Aug 29 '20 at 18:30
  • I still think the first thing to try would be to just double click it. I've never found a file yet that one of my compression apps couldn't deal with without needing any manual intervention from me. Back in the old days I'd sometimes need Split&Concat, but not in the last decade or so. – Tetsujin Aug 29 '20 at 18:45
  • @Tetsujin With many compression formats you can tell for sure if a given file is complete. If it's incomplete then it's sane to assume it has been split. Then finding subsequent parts and concatenating transparently before decompressing is the right thing to do. Here I believe somebody used split before bzip2; each archive is complete. If an archive itself is complete then how can the app tell if the resulting file is incomplete? It can be any format or a random blob. If any general purpose decompressor tries to search for additional parts after decompressing then I say it does wrong. – Kamil Maciorowski Aug 29 '20 at 19:30

These digits are not "formats" nor "extensions"; each is just a part of the respective filename. The content matters.

If the compressed files decompress without errors then I suspect all you need is to concatenate the resulting files in the right order. The natural order is probably the right one. Here I assume the last file is split.csv.15. Adjust the approach if needed.

In a shell that expands {0..15} (e.g. in Bash) the following command should work (warning: it will overwrite result.csv):

cat split.csv.{0..15} > result.csv

In any sane shell you can specify all the names explicitly:

cat split.csv.0 split.csv.1 split.csv.2 … > result.csv

(In case it's not obvious: replace with the rest of the filenames.)

Note cat split.csv.* is probably not a good idea. Even if there are no extra files matching the pattern (e.g. the .bz2 files), the shell will probably expand split.csv.* to filenames in the wrong order. Compare the output of echo split.csv.*.

  • This seems like a really, really complicated way to do a simple task. – Tetsujin Aug 29 '20 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.