# How can I run a command for multiple files?

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? • Is the doubling of$2 intentional? Seems like cut would be a little simpler to use here. Nov 19 '19 at 0:08

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


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