我想将特定文件(XXXXXXX_Abstract_TOC.txt
,XXXXXXX_Chapter1.txt
,XXXXXXX_Chapter2.txt
,XXXXXXX_Chapter3.txt
,XXXXXXX_Chapter4.txt
,XXXXXXX_Conclusion.txt
合并到一个文件中基于来自文本文件的特定数字( /util_files/list_NRPs.txt )。
注意:X是[0-9]
数字
list_NRPs.txt 包含如下内容:
0030001
0030002
0030004
...
在 / All_Files 文件夹中,我有以下文件:
0030001_Abstract_TOC.txt
0030001_Chapter1.txt
0030001_Chapter2.txt
0030001_Chapter3.txt
0030001_Chapter4.txt
0030001_Conclusion.txt
0030002_Abstract_TOC.txt
0030002_Chapter1.txt
0030002_Chapter2.txt
0030002_Chapter3.txt
0030002_Chapter4.txt
0030002_Conclusion.txt
0030004_Abstract_TOC.txt
0030004_Chapter1.txt
0030004_Chapter2.txt
0030004_Chapter3.txt
0030004_Chapter4.txt
0030004_Conclusion.txt
...
对于 list_NRPs.txt 中的每个XXXXXXX,我想合并XXXXXXX_Abstract_TOC.txt
,XXXXXXX_Chapter1.txt
,XXXXXXX_Chapter2.txt
,XXXXXXX_Chapter3.txt
,{{1} },XXXXXXX_Chapter4.txt
加入XXXXXXX_Conclusion.txt
。
/ All_Files 文件夹中的最终流程为:
XXXXXXX_All.txt
我想从0030001_Abstract_TOC.txt
0030001_Chapter1.txt
0030001_Chapter2.txt
0030001_Chapter3.txt
0030001_Chapter4.txt
0030001_Conclusion.txt
0030001_All.txt
0030002_Abstract_TOC.txt
0030002_Chapter1.txt
0030002_Chapter2.txt
0030002_Chapter3.txt
0030002_Chapter4.txt
0030002_Conclusion.txt
0030002_All.txt
0030004_Abstract_TOC.txt
0030004_Chapter1.txt
0030004_Chapter2.txt
0030004_Chapter3.txt
0030004_Chapter4.txt
0030004_Conclusion.txt
0030004_All.txt
...
开始,但我不知道如何继续。
我该怎么做?
答案 0 :(得分:1)
您可以使用globbing连接匹配list_NRPs.txt
文件中每行的多个文件:
while read -r ch; do
cat "/All_Files/$ch"* > "/All_Files/${ch}_All.txt"
done < /util_files/list_NRPs.txt