我有多个文件要与 cat
连接。
比方说
File1.txt
foo
File2.txt
bar
File3.txt
qux
我想连接,使最终文件看起来像:
foo
bar
qux
用通常的 cat File*.txt > finalfile.txt
foo
bar
qux
正确的做法是什么?
最佳答案
你可以这样做:
for f in *.txt; do (cat "${f}"; echo) >> finalfile.txt; done
在运行上述命令之前,请确保文件 finalfile.txt
不存在。
如果你被允许使用 awk
你可以这样做:
awk 'FNR==1{print ""}1' *.txt > finalfile.txt
https://stackoverflow.com/questions/8183191/