Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use awk for a compressed file

How can I change the following command for a compressed file?

awk 'FNR==NR { array[$1,$2]=$8; next } ($1,$2) in array { print $0 ";" array[$1,$2] }' input1.vcf input2.vcf 

The command working fine with normal file. I need to change the command for compressed files.

like image 610
AKR Avatar asked Oct 30 '12 10:10

AKR


People also ask

Does awk work on zipped files?

No, Awk just reads and writes text, and only the files you tell it to. You give it - to say "read standard input, not a file on disk". Pipe to gzip to compress the output. zcat | awk stuff ...

Can awk modify file?

In our awk code, we don't have to handle each file separately or manually control the redirection. Instead, we just change the text as the awk command reads each line from the files. The inplace extension takes care of which file is currently being processed and writes any changes back to the file automatically.

How do I grep compressed files?

Unfortunately, grep doesn't work on compressed files. To overcome this, people usually advise to first uncompress the file(s), and then grep your text, after that finally re-compress your file(s)… You don't need to uncompress them in the first place. You can use zgrep on compressed or gzipped files.

What is awk '{ print $2 }'?

awk '{ print $2; }' prints the second field of each line. This field happens to be the process ID from the ps aux output. xargs kill -${2:-'TERM'} takes the process IDs from the selected sidekiq processes and feeds them as arguments to a kill command.


1 Answers

You need to read them compressed files like this:

awk '{ ... }' <(gzip -dc input1.vcf.gz) <(gzip -dc input2.vcf.gz) 

Try this:

awk 'FNR==NR { sub(/AA=\.;/,""); array[$1,$2]=$8; next } ($1,$2) in array { print $0 ";" array[$1,$2] }' <(gzip -dc input1.vcf.gz) <(gzip -dc input2.vcf.gz) | gzip > output.vcf.gz 
like image 178
Steve Avatar answered Oct 13 '22 20:10

Steve