I'm trying to concatenate horizontally a number of files (1000) *.txt
in a folder.
How can I loop over the files using the "paste" function?
NB: all the *.txt
files are in the same directory.
I'm trying to concatenate horizontally a number of files (1000) *.txt
in a folder.
How can I loop over the files using the "paste" function?
NB: all the *.txt
files are in the same directory.
为什么要循环?您可以使用通配符。
paste *.txt > combined.txt
一般来说,这只是一个调用paste *.txt
(并重定向输出:paste *.txt > output.txt
,就像@zx 所做的那样)的问题。试试看,但你会产生一些非常长的行。如果paste
无法处理您将生成的行长,则必须使用没有行长限制的脚本语言(如 perl 或 python)重现其效果。
另一个可能的症结在于,如果您的 shell 无法在 glob 的扩展中处理这么多参数*.txt
。同样,您可以使用脚本解决该问题。如果这是您的情况,这样做很容易,请在此处告诉我们。
PS。鉴于这样paste
做,循环不会为你做:你(大概)需要在输出中并排的文件内容,而不是一个接一个。