Home » Linux » How can I view a compressed file content

How can I view a compressed file content

Posted by: admin January 30, 2018 Leave a comment


I have a very large file as: filename.bz2, how can I view the file content and do some commands like awk to extract some data into another file without decompress it ? I tried head -50 filename.bz2 to view the first 50 lines, but it prints out rubbish and not the what I supposed to view from the file.


You can use bzcat and pipe its output to awk or whatever tool you use, but it is essentially nothing different from extracting a file and then processing it.

$ echo '1' > test
$ bzip2 test
$ bzcat test.bz2


Have you tried bzcat?

bzcat filename.bz2 | head -50

Read more