[英]Merge files based on a list of pairs
I have files in a directory, and a list of pairs of filenames eg 我在目录中有文件,并且有一对文件名对,例如
list:
FileA File1
FileB File2
FileC File3
I would like to merge each pair of files into one file. 我想将每对文件合并为一个文件。 I learned that it's possible to merge all files in a directory based on a list using this command
我了解到可以使用此命令基于列表合并目录中的所有文件
xargs < list.text cat > merged_file.txt
But I am not sure how to do this on a line by line basis (ie pairing up files) as in my case. 但是我不确定如何像我的情况那样逐行地执行此操作(即配对文件)。
The resulting files should be called FileA_File1_merged.txt 生成的文件应名为FileA_File1_merged.txt
Read the list
file line by line, and cat
files to a merged one: 逐行读取
list
文件,然后将cat
文件合并到一个文件中:
while read line; do
cat $line > "$line.merged"
done < list
Attention result file name will contain spaces and .merged
"extension". 注意结果文件名将包含空格和
.merged
“扩展名”。 To replace spaces w/ -
you may use bash pattern replacement: ... >"${line/ /-}.merged"
. 要用空格替换空格
-
您可以使用bash模式替换: ... >"${line/ /-}.merged"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.