Linux 如何将 awk 用于压缩文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13137501/
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 to use awk for a compressed file
提问by AKR
How can I change the following command for a compressed file?
如何更改压缩文件的以下命令?
awk 'FNR==NR { array[,]=; next } (,) in array { print awk '{ ... }' <(gzip -dc input1.vcf.gz) <(gzip -dc input2.vcf.gz)
";" array[,] }' input1.vcf input2.vcf
The command working fine with normal file. I need to change the command for compressed files.
该命令对普通文件工作正常。我需要更改压缩文件的命令。
采纳答案by Steve
You need to read them compressed files like this:
您需要像这样读取它们的压缩文件:
awk 'FNR==NR { sub(/AA=\.;/,""); array[,]=; next } (,) in array { print bzip2 -dc input1.vcf.bz2 input2.vcf.bz2 | awk 'FNR==NR { array[,]=; next } (,) in array { print gzip -dc input1.vcf.gz input2.vcf.gz | awk 'FNR==NR { array[,]=; next } (,) in array { print | bzip2 >output.vcf.bz2
";" array[,] }'
";" array[,] }'
";" array[,] }' <(gzip -dc input1.vcf.gz) <(gzip -dc input2.vcf.gz) | gzip > output.vcf.gz
Try this:
尝试这个:
| gzip >output.vcf.gz
回答by Mackie Messer
zcat FILE | awk '{ ...}'
or
或者
##代码##EDIT:
编辑:
To write compressed output just append
要写入压缩输出只需追加
##代码##or
或者
##代码##This will work with any program that prints results to standard output.
这适用于任何将结果打印到标准输出的程序。
BTW: Editing such large command lines gets tedious very quickly. You should consider writing a small shell script to do the job. This has the additional benefit that you don't have to remember the entire thing and can easily repeat the command or modify it if necessary.
顺便说一句:编辑如此大的命令行很快就会变得乏味。您应该考虑编写一个小的 shell 脚本来完成这项工作。这有一个额外的好处,您不必记住整个事情,并且可以轻松地重复命令或在必要时修改它。
A good starting point for Linux shell programming is the Bash Programming Inroductionby Mike G.
Linux shell 编程的一个很好的起点是Mike G的Bash 编程介绍。
回答by runlevel0
I wouldn't be able to tell which of all these methods works best, zcat is at least quicker to type ;)
我无法分辨出所有这些方法中哪一种效果最好,zcat 至少输入速度更快;)