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
How can I view a compressed file content
提问by Jury A
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.
我有一个非常大的文件:filename.bz2
,如何查看文件内容并执行一些命令,例如awk
将一些数据提取到另一个文件中而不解压缩?我试图head -50 filename.bz2
查看前 50 行,但它打印出垃圾而不是我应该从文件中查看的内容。
采纳答案by Lev Levitsky
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.
您可以使用bzcat
它的输出并将其通过管道传输到awk
您使用的任何工具,但这与提取文件然后处理它本质上没有什么不同。
$ echo '1' > test
$ bzip2 test
$ bzcat test.bz2
1