So I have 128 files with two columns. I want to match them by the values in the first column and add the values in the second column from each file to a single file.
I was able to kinda of find a solution here:
From: https://unix.stackexchange.com/questions/159961/merging-2-files-with-based-on-field-match
awk 'FNR==NR{a[$1]=$2;next} ($1 in a) {print $1,a[$1],$2}' file2 file1
It does what I want, however I need for this to go through every file in the folder.
Is there away to make this command loop through all the files in the folder or is there a better method all together?
Example: Input
File 1:
gene_id normalized_count
A1BG|1 42.3332
A1CF|29974 165.6696
A2BP1|54715 0.0000
A2LD1|87769 138.1270
A2ML1|144568 2.7612
A2M|2 7310.6121
A4GALT|53947 348.3663
A4GNT|51146 0.0000
File 2:
gene_id normalized_count
A1BG|1 18.2019
A1CF|29974 129.6194
A2BP1|54715 2.2063
A2LD1|87769 65.3116
A2ML1|144568 0.0000
A2M|2 3415.8632
A4GALT|53947 83.2874
A4GNT|51146 0.0000
File 3:
gene_id normalized_count
A1BG|1 8.6285
A1CF|29974 97.6385
A2BP1|54715 0.0000
A2LD1|87769 200.5540
A2ML1|144568 0.0000
A2M|2 984.0736
A4GALT|53947 24.0690
A4GNT|51146 0.4541
Desired output
gene_id normalized_count
A1BG|1 42.3332 18.2019 8.6285
A1CF|29974 165.6696 129.6194 97.6385
A2BP1|54715 0 2.2063 0
A2LD1|87769 138.127 65.3116 200.554
A2ML1|144568 2.7612 0 0
A2M|2 7310.6121 3415.8632 984.0736
A4GALT|53947 348.3663 83.2874 24.069
A4GNT|51146 0 0 0.4541
For the desired output I don't care how the column labels end up looking.
Again my problem is that I have to do this for hundreds of files at once to produce one file.
Here are some other similar problems with solutions https://unix.stackexchange.com/questions/122919/merge-2-files-based-on-all-values-of-the-first-column-of-the-first-file
But they only had to do this for a few files.
Edit: both Nathan's and joepd worked and produced similar output Thank you!
Nathan's solution will produce output space delimited
joepd's will produce output that had the header (with original tab separated), and the first column separated by two spaces and the rest space delimited.