使用SED Concat多个文件

时间:2016-08-03 11:02:13

标签: windows unix sed

我有一个带文件名列表的txt文件,其中包含文件路径。如何将所有文件连接到单个文件?

EX:

One.txt content >> first file content
two.txt content >> second file content
three.txt content >> third file content

allFiles.txt contains these the below lines
one.txt
two.txt
three.txt

我需要将allFiles.txt连接到包含以下行的output.txt文件

first file content
second file content
third file content

1 个答案:

答案 0 :(得分:0)

while read fname
do
 sed '1' "$fname" >> newfile.txt # You need to append so '>>'
done<allFiles.txt

但是如果您需要所有*.txt个文件

可以像

一样简单
shopt -s globstar
sed '' **/*.txt 1>>/outfile 2>/dev/null # errors for .txt directories are suppressed
shopt -u globstar