简体   繁体   English

当使用Bash脚本从excel文件中提取目录名称时,如何从目录中复制特定文件

[英]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.

相关问题 如何使用cp linux将多个目录中的同名文件复制到新目录中 - How to copy a file with the same name from multiple directories into new directories using cp linux 从不同目录复制特定文件而不更改文件扩展名 - Copy specific files from different directories without changing file extension Bash在所有目录中获取具有名称的特定文件并运行脚本 - Bash get specific file with name in all directories and run script bash脚本将文件复制到多个指定目录 - bash script to copy file into multiple specified directories 在Bash脚本中删除包含特定文件的目录 - Delete directories with specific files in Bash Script 通过bash脚本与来自多个目录的文件进行交互 - Interacting with files from multiple directories via bash script bash脚本使用从远程目录到本地文件夹的密码来sftp文件 - bash script to sftp files with a password from remote directories to local folders 一个 bash 脚本,用于一次重命名不同目录中的文件 - A bash script to rename files from different directories at once Ubuntu bash脚本从多个目录中删除旧的备份文件 - Ubuntu bash script to delete old backup files from multiple directories 如何在忽略某些目录的同时找到超过特定大小的所有文件(使用bash脚本) - How do I find all files above a certain size while ignoring certain directories (using a bash script)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM