将目录中所有*.txt文件合并为一个大文本文件的最快和最实用的方法是什么?

目前我正在使用cygwin的窗口,所以我可以访问BASH。

Windows shell命令也会很好,但我怀疑有没有一个。


当前回答

使用shell最实用的方法是cat命令。其他方式包括,

awk '1' *.txt > all.txt
perl -ne 'print;' *.txt > all.txt

其他回答

Windows shell命令类型可以这样做:

type *.txt > outputfile.txt

Type Type命令还将文件名写入stderr,这些文件名不会被>重定向操作符捕获(但会显示在控制台上)。

所有这些都令人讨厌....

ls | grep *.txt | while read file; do cat $file >> ./output.txt; done;

简单的东西。

这会将输出追加到all.txt

cat *.txt >> all.txt

这将覆盖all.txt

cat *.txt > all.txt

这种方法怎么样?

find . -type f -name '*.txt' -exec cat {} + >> output.txt

使用shell最实用的方法是cat命令。其他方式包括,

awk '1' *.txt > all.txt
perl -ne 'print;' *.txt > all.txt