Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I view a compressed file content

Tags:

linux

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.

like image 558
Jury A Avatar asked Sep 28 '12 20:09

Jury A


People also ask

How do you view the contents in a zipped file?

Also, you can use the zip command with the -sf option to view the contents of the . zip file. Additionally, you can view the list of files in the . zip archive using the unzip command with the -l option.

How can I view a zip file without extracting it?

Viewing Zip File Contents Without Extracting Lucky for you, the unzip command has the -l option that displays the contents of a zip file without extracting them. To view a ZIP file's contents, run the unzip command to list ( -l ) the zip file's ( newdir. zip ) contents without extracting them.

Why can't I open compressed files?

Zip files may refuse to open if they are not properly downloaded. Also, incomplete downloads occur when files get stuck due to issues like bad internet connection, inconsistency in network connection, all of which can cause transfer errors, affect your Zip files, and make them unable to open.

Can anyone open a compressed file?

Just like regular digital folders, you can easily open a ZIP file on almost any computer or operating system. But, unlike regular folders, you need more than just a simple double-click to use the files inside it.


1 Answers

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
1
like image 152
Lev Levitsky Avatar answered Oct 12 '22 12:10

Lev Levitsky