Linux 如何查看压缩文件的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12646843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:27:56  来源:igfitidea点击:

How can I view a compressed file content

linux

提问by Jury A

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

我有一个非常大的文件:filename.bz2,如何查看文件内容并执行一些命令,例如awk将一些数据提取到另一个文件中而不解压缩?我试图head -50 filename.bz2查看前 50 行,但它打印出垃圾而不是我应该从文件中查看的内容。

采纳答案by Lev Levitsky

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

您可以使用bzcat它的输出并将其通过管道传输到awk您使用的任何工具,但这与提取文件然后处理它本质上没有什么不同。

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

回答by janisz

Have you tried bzcat?

你试过bzcat吗?

bzcat filename.bz2 | head -50

Read more

阅读更多