bash 根据另一个文件中的匹配将特定文件移动到文件夹

bash 根据另一个文件中的匹配将特定文件移动到文件夹

.vcf我正在尝试将中的每个文件 mv 到id所在的variants folder文件夹中。in将始终在变体文件夹中具有 a 的 id 。以开头的行始终与 中的文件夹完全匹配。中可能有多个文件夹,但 中只有一个匹配项。也可能有多个 id,但在./home/cmccabe/f2.vcffile$2file.vcffileR_2019-v5.6/home/cmccabe/f2/home/cmccabe/f2file.vcf/home/cmccabe/f1/variants

/home/cmccabe/f2当在文件夹 in和R_2019in之间找到匹配项时file,in 中的 id$2将作为/home/cmccabe/f1/variants找到.vcf。然后,每个文件都会移动到新子文件夹中.vcf的匹配文件夹中。确实执行但没有文件被移动。谢谢 :)。/home/cmccabe/f2variantsbash

文件在/home/cmccabe/f1

IonCode_0007 19-0004-La-Fi
IonCode_0009 19-0005-Last-Firs
IonCode_0013 190320-Control
R_2019_03_12_13_59_54_user_S5-0271-100-v5.6_xxx_xxx_xxx_xxx_xx_x_xxx

变体文件夹/home/cmccabe/f1

19-0004-La-Fi.vcf
19-0005-Last-Firs.vcf
190320-Control.vcf

当前结构/home/cmccabe/f2

R_2019_03_12_13_59_54_user_S5-0271-100   ---parent directory ---
   - bam    --- sub-folder ---
   - qc     --- sub-folder ---

所需的结构/home/cmccabe/f2

R_2019_03_12_13_59_54_user_S5-0271-100   ---parent directory ---
   - bam    --- sub-folder ---
   - qc     --- sub-folder ---
   - variants    --- new sub-folder ---
     - 19-0004-La-Fi.vcf
     - 19-0005-Last-Firs.vcf
     - 190320-Control.vcf

可能的重击

for file in /home/cmccabe/f1/variants/*.vcf ; do
  # Grab file prefix
  bname=$(basename $file) # strip of path
  VCF="$(echo $bname|cut -d. -f1)" # remove .vcf extension
  f=$(printf '%s' /home/cmccabe/f1/file/${VCF})  ## # Find matching id
  FILE2=$(awk '{print $2}' $f) # set VCF lookup to column
    for RDIR in /home/cmccabe/f1/file/R_2019* ; do FOLDER=${RDIR%%-v5.6*}; done  ## trim R_2019 line in file from -v5.6 and store in FOLDER
  if [[ $VCF = $FILE2 ]] # only execute file on match
  then
      mkdir -p /home/cmccabe/f2/$FOLDER/variants  ## create variants sub-folder
       mv /home/cmccabe/f1/file/$VCF /home/cmccabe/f2/$FOLDER/variants  ## move vcf to folder
  fi  ## end if
done  ## close loop

相关内容