在下面的bash
中,我尝试将/home/cmccabe/QC/test/metrics.txt
中的单个文本文件复制3次。然后,使用/home/cmccabe/QC/analysis.txt
中的第3-5行(始终相同)重命名3个文本文件中的每一个。但是,我收到一个错误,不知道如何解决它。谢谢你:)。
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
status: complete
id names:
00-0000_Last-First
01-0101_LastN-FirstN
02-0202_La-Fi
尝试
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
所需输出(单列数据)
00-0000_Last-First_meterics.txt
01-0101_LastN-FirstN_metrics.txt
02-0202_La-Fi_metrics.txt
答案 0 :(得分:1)
您知道,您可以使用sed
获取新文件名
现在您可以使用printf获取mv命令:
printf "mv metrix.txt %s\n" "$(sed '1,2 d' /home/cmccabe/QC/test/metrics.txt)"
现在输出的输出与<()
的常规命令一样。
source <(printf "mv metrix.txt %s\n" "$(sed '1,2 d' /home/cmccabe/QC/test/metrics.txt)")
source
可以用点替换,并希望在文件名中看到双引号(可能在其中有空格):
. <(printf 'mv metrix.txt "%s"\n' "$(sed '1,2 d' /home/cmccabe/QC/test/metrics.txt)")