Suppose we have these two files:
$ cat ABC.txt ABC DEF $ cat PQR.txt PQR XTZ And we want to form a new file with the 1st column of each file. This can be achieved by:
$ paste -d ' ' <(cut -d ' ' -f 1 ABC.txt) <(cut -d ' ' -f 1 PQR.txt ) ABC PQR But I want to use this with tons of files in the input, not only ABC.txt and PQR.TXT, but a lot of them. How we can generalize this situation to pass each file in the collection to cut and then pass all the outputs to paste (I know that this may be done better with awk but I want to know how to solve this using this approach).
Edit 1
I have discovered a dirty, dirty way of doing this:
$ str=''; for i in *.txt; \ do str="${str} <(cut -d ' ' -f 1 ${i})"; \ done ; \ str="paste -d ' ' $str"; \ eval $str But please, free my soul with an answer that does not involve going to Computer Science Hell.
Edit 2
Each file can have n rows, if this matters.