Bash脚本用于读取CSV文件和搜索目录以查找要复制的文件

时间:2018-01-09 18:47:01

标签: bash csv

我正在创建bash脚本来读取CSV文件(逗号描绘)。该文件包含另一个目录中文件的部分名称。然后,我需要使用这些名称并使用它们来搜索目录并将正确的文件复制到新文件夹。

我能够读取csv文件。但是,csv文件只包含部分文件名,因此我需要使用通配符在目录中搜索文件。我无法让通配符在目录中工作。

CSV文件格式(在记事本中):

12
13
14
15

目标目录中的示例文件名:

IXI12_asfds.nii
IXI13_asdscds.nii
IXI14_aswe32fds.nii
IXI15_asf432ds.nii

所有文件的前缀相同:IXI。 csv文件包含出现在前缀后面的每个目标文件的唯一编号。文件名的中间部分对每个文件都是唯一的。

#!/bin/bash
# CSV file with comma delineated numbers. 
# CSV file only contains part of the file name. Need to add IXI to the 
beginning, and search with a wildcard at the end. 

input="CSV_file.csv"
while IFS=',' read -r file_name1
do
   name=(IXI$file_name1)
   cp $name*.nii /newfolder

done < "$input"

我不断得到的错误是说没有能够识别具有相应名称的文件夹。

0 个答案:

没有答案