I have input files in one directory. All the input files have the same format and I'd like to join certain columns from these input files into one output file.
For example:
in File1
Adam 0.5 a1
Bills 0.7 b1
Carol 0.8 c1
Dean 0.4 d1
in File2
Adam 0.4 a2
Carol 0.8 c2
Evan 0.9 e2
in File3
Bills 0.6 b3
Carol 0.7 c3
Evan 0.1 e3
I'd like to join the third column from all input files by using the first column as a key. So the output may look like
Adam a1 a2 NA
Bills b1 NA b3
Carol c1 c2 c3
Dean d1 NA NA
Evan NA e2 e3
Because the number of input files are varied, the number of columns in output are also varied. The number of input files are at least 200 and can be maximum at 10,000.
I couldn't find a simple way to use 'for', 'awk', 'join', 'cut' to solve this problem. And yes, I can write a Python or Perl script to solve this problem but I wonder if this can be done using bash script alone?
ps. I tried to search for a solution before asking this question but couldn't find it. If this kind of question is already asked, please point me to the answer.
See Question&Answers more detail:os