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

46,250

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
Share:
46,250
user1458512
Author by

user1458512

Updated on December 13, 2020

Comments

  • user1458512
    user1458512 over 3 years

    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?