I have an unknown number of input files that all match a search string, let's say *.dat, and all have 2 columns of data and equal number of rows. In bash I need to take the 2nd column in each file and append it as a new column in a singular merged file.
Eg:
>>cat File1.dat
1 A
2 B
3 C
>>cat File2.dat
4 D
5 E
6 F
>>cat combined.dat
A D
B E
C F
Here is the code I have tried, the approach I have gone for is to try to loop and append:
for filename in $(ls *.dat); do paste combined.dat <(awk '{print $2}' $filename) >> combined.dat; done
The output format can be anything so long as its tab delimited, and the key is it must work on any number of input files up to...100 approx, where the number isn't known in advance.