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

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

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


当前回答

请记住,对于目前给出的所有解决方案,shell决定文件连接的顺序。巴什,IIRC,这是字母顺序。如果顺序很重要,您应该适当地命名这些文件(01file.txt, 02file.txt,等等),或者按照您想要连接的顺序指定每个文件。

$ cat file1 file2 file3 file4 file5 file6 > out.txt

其他回答

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

type *.txt > outputfile.txt

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

这种方法怎么样?

find . -type f -name '*.txt' -exec cat {} + >> output.txt
type [source folder]\*.[File extension] > [destination folder]\[file name].[File extension]

例如:

type C:\*.txt > C:\1\all.txt

这将采取所有的txt文件在C:\文件夹,并将其保存在C:\1文件夹的名称为all.txt

Or

type [source folder]\* > [destination folder]\[file name].[File extension]

例如:

type C:\* > C:\1\all.txt

这将获取文件夹中所有文件,并将Content放在C:\1\all.txt中

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

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

请记住,对于目前给出的所有解决方案,shell决定文件连接的顺序。巴什,IIRC,这是字母顺序。如果顺序很重要,您应该适当地命名这些文件(01file.txt, 02file.txt,等等),或者按照您想要连接的顺序指定每个文件。

$ cat file1 file2 file3 file4 file5 file6 > out.txt