【问题标题】:Concat multiple files using SED使用 SED 连接多个文件
【发布时间】:2016-12-09 01:35:23
【问题描述】:

我有一个包含文件名列表的 txt 文件,其中包含文件路径。如何将所有文件合并为一个文件?

前:

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

【问题讨论】:

  • 你真的需要 sed 吗? cat allFiles.txt | xargs cat 应该这样做。
  • cat allFiles.txt | xargs 猫 >> output.txt。它有效

标签: windows unix sed


【解决方案1】:
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

【讨论】:

  • 仅限特定文件,并非所有文件都在同一个目录中。因此创建了一个包含这些文件名的 txt 文件。
  • @Neo :那么我的第一个解决方案就是给你的。如果符合要求,请采纳。
猜你喜欢
  • 2020-09-27
  • 1970-01-01
  • 2011-04-06
  • 2013-06-12
  • 2019-04-13
  • 1970-01-01
  • 2021-11-06
  • 2017-11-08
  • 2011-03-12
相关资源
最近更新 更多