I am searching for a way to decompress a bzip2 compressed text file, change the content (adding new content, sorting etc.) and compress it again through pipelines.
I already found a way to do this but unfortunately I have to use another file as the recompressed output since bzip2 does not allow to use the same file in this case.
Here is my code:
bzip2 -dc file.bz2 | sort | bzip2 -9 > file_2.bz2 If I use the same file I get following error:
bzip2: Compressed file ends unexpectedly; perhaps it is corrupted? *Possible* reason follows. bzip2: Success Input file = file.bz2, output file = (stdout) It is possible that the compressed file(s) have become corrupted. You can use the -tvv option to test integrity of such files. You can use the `bzip2recover' program to attempt to recover data from undamaged sections of corrupted files. Any solutions how I can solve the issue?
Thanks in advance!