NewUsr_stat
NewUsr_stat

Reputation: 2571

Loop "paste" function over multiple files in the same folder

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.

Upvotes: 2

Views: 3029

Answers (2)

zx8754
zx8754

Reputation: 56054

Why loop? You can use wildcards.

paste *.txt > combined.txt

Upvotes: 4

alexis
alexis

Reputation: 50190

In general, it would be a question of just calling paste *.txt (and redirecting the output: paste *.txt > output.txt, as @zx did). Try it, but you'll be generating some enormously long lines. If paste can`t handle the line length you'll be generating, you'll have to reproduce its effect using a scripting language that has no line length limit, like perl or python.

Another possible sticking point is if your shell can't handle this many arguments in the expansion of the glob *.txt. Again, you can solve that with a script. It's easy to do so if that's your situation, let us know here.

PS. Given what paste does, looping is not going to do it for you: You (presumably) need the file contents side by side in the output, not one after the other.

Upvotes: 1

Related Questions