[英]bash to copy file 3 times and rename each using lines in another file
In the bash
below I am trying to copy the single text file in /home/cmccabe/QC/test/metrics.txt
3 times. 在下面的bash
中,我尝试将单个文本文件复制到/home/cmccabe/QC/test/metrics.txt
3次。 Each one of the 3 text files is then renamed using lines 3-5 (always the same), from /home/cmccabe/QC/analysis.txt
. 然后使用3-5行(始终相同)从/home/cmccabe/QC/analysis.txt
重命名3个文本文件中的每个文件。 However, I am getting an error and not sure how to fix it. 但是,我遇到一个错误,不确定如何解决。 Thank you :). 谢谢 :)。
metrics.txt ( tab-delimited
) metrics.txt ( tab-delimited
)
R_Index ISP Loading Pre-Enrichment Total Reads Read Length Key Signal Usable Sequence Enrichment Polyclonal Low Quality Test Fragment Aligned Bases Unaligned Bases Exception
1 89 . 78402052 201 77 61 98.6 29.2 10.4 79 98.8 1.2
analysis.txt analysis.txt
status: complete
id names:
00-0000_Last-First
01-0101_LastN-FirstN
02-0202_La-Fi
attempt 尝试
LinesToSkip=2
((StartLine=$LinesToSkip+1))
files=($(cat /home/cmccabe/QC/test/metrics.txt ))
i=1
while read -r new_name
do
mv "${files[$i]}" "$new_name"
((i=$i+1))
done < <(sed -n "${StartLine},\$p" /home/cmccabe/QC/analysis.txt)
mv: cannot stat ‘ISP’: No such file or directory
mv: cannot stat ‘Loading’: No such file or directory
mv: cannot stat ‘Pre-Enrichment’: No such file or directory
desired output (single column of data) 所需的输出 (单列数据)
00-0000_Last-First_meterics.txt
01-0101_LastN-FirstN_metrics.txt
02-0202_La-Fi_metrics.txt
You foundm, that you can get the new filenames with sed
. 您发现,可以使用sed
获取新文件名。
Now you can get mv commands using printf: 现在您可以使用printf获得mv命令:
printf "mv metrix.txt %s\n" "$(sed '1,2 d' /home/cmccabe/QC/test/metrics.txt)"
Now get the output executed like the were regular commands with <()
. 现在,使用<()
像常规命令一样执行输出。
source <(printf "mv metrix.txt %s\n" "$(sed '1,2 d' /home/cmccabe/QC/test/metrics.txt)")
source
can be replaced by a dot and would like to see double quotes in the filename (might have a space in it): source
可以用点代替,并希望在文件名中看到双引号(可能有空格):
. <(printf 'mv metrix.txt "%s"\n' "$(sed '1,2 d' /home/cmccabe/QC/test/metrics.txt)")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.