[英]How to copy specific files from directories, while the directories name was extracted from an excel file using Bash script
I'm new in Bash and I have a list of names of directories stored in an excel file. 我是Bash的新手,我有一个存储在excel文件中的目录名称列表。 I'd like to find those directories (they are located in different location at the computer) and to copy from each directory specific files (list of 4 files that ends with specific endings) to a remote computer. 我想找到这些目录(它们位于计算机的不同位置),并将每个文件中的特定文件(以特定结尾结尾的4个文件的列表)复制到远程计算机。
For examples: 举些例子:
For a name of directory at the excel sheet - "NA123", I'd like to find it and copy it's partial content to a remote computer, for example copy the files: samples-sheet.csv, toInfo.xml, newfiles.gz, todo.csv to the remote computer, under a folder name "NA123". 对于Excel工作表上的目录名称-“ NA123”,我想找到它并将其部分内容复制到远程计算机,例如,复制文件:samples-sheet.csv,toInfo.xml,newfiles.gz ,todo.csv,到文件夹名称为“ NA123”的远程计算机。
How do I begin to do that? 我该如何开始呢?
****Editing to give an example of how it needs to be***** ****编辑以举例说明如何实现*****
A short example of the csv is as below: CSV的简短示例如下:
A
1 14RD00129_TS1_01
2 SD-2015-06_01
3 US-005
4 RA99
All the names at the csv are directories that can be found under /home/bella/samples
under 3 different folders: some will be at /home/bella/samples/gruop_1
, some at: /home/bella/samples/gruop_2
, and some at: /home/bella/samples/gruop_3
csv上的所有名称都是可以在/home/bella/samples
3个不同文件夹下找到的目录:一些位于/home/bella/samples/gruop_1
,一些位于/home/bella/samples/gruop_2
,以及一些位于: /home/bella/samples/gruop_3
So first I need to iterate through the csv file, to locate the match directory at my computer, then I need to copy 4 specific files to a remote computer with the same name of directory. 因此,首先我需要遍历csv文件,以在我的计算机上找到匹配目录,然后我需要将4个特定文件复制到具有相同目录名的远程计算机上。 Hope this is clearer... 希望这更清楚...
I guess you CSV file should only consist of directory names then, since there's only one column. 我想您的CSV文件应该只包含目录名称,因为只有一列。 I assume there is no header line in the CSV ( A
in your example) and no line number. 我假设CSV中没有标题行(在您的示例中为A
),也没有行号。 You can take this as a starting point: 您可以以此为起点:
samples='/home/bella/samples'
while IFS= read -r line; do
dir=$(find "$samples"/gruop_{1..3} -type d -name "$line")
scp "$dir"/{samples-sheet.csv,toInfo.xml,newfiles.gz,todo.csv} \
user@host.com:"/path/to/$line"
done < 'file.csv'
Basically, you could do something like: 基本上,您可以执行以下操作:
# create the directory on the remote:
ssh remote-ip 'mkdir -p NA123'
# copy the files to the remote in the directory just created
for f in samples-sheet.csv toInfo.xml newfiles.gz todo.csv; do scp $f remote-ip:NA123/; done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.