user1458512
user1458512

Reputation: 159

How to cut multiple columns from several files and print the output to different files

I have several files and I only want to take specific columns from it. At the moment, I am using the following code:

$cut -f 1,2,5 AD0062-C.vcf > cutAD0062.txt

However, to speed up the process I was wondering if I could cut the same columns (fields 1,2,5) in multiple files and then print the output to several different files. I.e columns 1,2,5 of files AD0063-C.vcf, AD0064-C.vcf, AD0065-C.vcf should output results to separate files: cutAD0063.txt, cutAD0064.txt, cutAD0065.txt?

Upvotes: 12

Views: 49375

Answers (1)

kev
kev

Reputation: 161624

You can write a for...loop:

for i in AD*-C.vcf
do
    cut -f 1,2,5 $i > cut${i%-C.vcf}.txt
done

Upvotes: 11

Related Questions