简体   繁体   English

Bash 循环遍历不同目录中的文件并打印输出

[英]Bash looping over files in different directories and print output

I have *.vcf , *.vcf.vcfidx and *.vcf.idx files in directory /mypath/mydir/ .我在/mypath/mydir/目录中有*.vcf*.vcf.vcfidx*.vcf.idx文件。 I want to loop over .vcf files only using command below (for file 1):我只想使用下面的命令(对于文件 1)遍历.vcf文件:

command for one vcf file:一个vcf文件的命令:

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?有人可以帮助循环所有 .vcf (不是vcf.vcfidxvcf.idx )文件并使用上面显示的命令/get/inthis/dir/指定目录/get/inthis/dir/每个文件的输出吗?

Just use glob pattern *.vcf :只需使用 glob 模式*.vcf

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

The glob pattern *.vcf will match only files ending in .vcf . glob 模式*.vcf将仅匹配以.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:如果您必须在特定目录(例如/foo/bar/搜索.vcf文件,请执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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