bash-如何匹配要在循环中使用的文件名 [英] bash - How to match files names to use in loop
本文介绍了bash-如何匹配要在循环中使用的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在每对文件上运行循环命令
I want to run a loop command on each pair of files
a_xxx.wig
b_xxx.wig
c_xxx.wig
a_xxx.bed
b_xxx.bed
c_xxx.bed
我想根据样本名称(a,b或c)来匹配文件,并让循环在每对中运行一条命令,而不必一次执行
I'd like to match the files based on sample name (a,b or c) and have the loop run a command through each of the pairs without having to do one at a time
for file in * do
bedtools intersect -a $sample.wig -b $sample > $sample.bed
done
任何想法或指示都将不胜感激
Any ideas or pointers would be greatly appreciated
推荐答案
wig
文件是输入,因此只需对其进行迭代即可.您可以提取文件名的一部分,以用作其他名称的基础".
The wig
file is the input, so just iterate over those. You can extract the portion of the file name to use as the "base" for the other names.
for file in *.wig; do
sample=${file%.wig}
bedtools intersect -a "$sample.wig" -b "$sample" > "$sample.bed"
done
这篇关于bash-如何匹配要在循环中使用的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文