1
$\begingroup$

I have a bunch of .vcf files in a folder and I want to run command below on all of them but doing that one by one manually is really painful. I am seeking for a way in terminal to do that simultaneously. The output would be a .txt file.

grep -v "##" /file.vcf | awk '{print $1"\t"$2"\t"$2"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10"\t"$11}' > /file.txt

Can you help please?

$\endgroup$
  • $\begingroup$ Is the doubling of $2 intentional? Seems like cut would be a little simpler to use here. $\endgroup$ – swbarnes2 Nov 19 '19 at 0:08
5
$\begingroup$

Assuming all your vcfs are in the same folder:

for file in *.vcf; do
    grep -v "##" ${file} | awk '{print $1"\t"$2"\t"$2"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10"\t"$11}' > ${file}.txt
done
| improve this answer | |
$\endgroup$
2
$\begingroup$

If additional CPUs are available:

CPU_COUNT=5
for file in *.vcf; do 
     (grep -v "##" ${file} | awk '{print $1"\t"$2"\t"$2"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10"\t"$11}' > ${file%.vcf}.txt) & let count+=1
     [[ $((count%CPU_COUNT)) -eq 0 ]] && wait
done

one-liner:

CPU_COUNT=5; for file in *.vcf; do (grep -v "##" ${file} | awk '{print $1"\t"$2"\t"$2"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10"\t"$11}' > ${file%.vcf}.txt) & let count+=1; [[ $((count%CPU_COUNT)) -eq 0 ]] && wait; done
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy