2016-08-03 64 views
0

我有一個包含文件路徑的文件名列表的txt文件。如何將所有文件連接到單個文件?Concat使用SED的多個文件

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 

我需要Concat的allFiles.txt到包含一個output.txt的文件,下面的線

first file content 
second file content 
third file content 
+1

你真的需要sed嗎? 'cat allFiles.txt | xargs貓'應該這樣做。 – patthoyts

+0

cat allFiles.txt | xargs cat >> output.txt。它的工作原理 – Neo

回答

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 
+0

只有特定的文件,並不是所有的文件都是同一個目錄。所以創建了一個包含這些文件名的txt文件。 – Neo

+0

@Neo:那麼我的第一個解決方案是給你的。請接受它,如果它符合要求。 – sjsam