简体   繁体   中英

Bash looping over files in different directories and print output

I have *.vcf , *.vcf.vcfidx and *.vcf.idx files in directory /mypath/mydir/ . I want to loop over .vcf files only using command below (for file 1):

command for one vcf file:

vcf-subset -c sample.txt vcffile1.vcf | bgzip  -c > output_vcfile1.vcf_.vcf.gz

Can someone please help loop over all the .vcf (not vcf.vcfidx or vcf.idx ) files and get the output for each file in designated directory /get/inthis/dir/ using the command shown above?

Just use glob pattern *.vcf :

for i in *.vcf; do echo "$i"; done

The glob pattern *.vcf will match only files ending in .vcf .

Your command:

for i in *.vcf; do
    vcf-subset -c sample.txt "$i" | bgzip  -c > /get/inthis/dir/output_"$i"_.vcf.gz
done

If you have to search for .vcf files in a specific directory eg /foo/bar/ , do:

for i in /foo/bar/*.vcf; do
    vcf-subset -c sample.txt "$i" | bgzip  -c > /get/inthis/dir/output_"${i##*/}"_.vcf.gz
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM