Hi, long time reader, first time poster.
I've done some searching so please if this is a repeated post excuse the duplicate, but what I have are two files roughly like so:
File 1:
A W
B X
C Y
D Z
File 2:
A 1
C 2
D 3
And what I would like to get out is something like:
A 1 W
B X
C 2 Y
D 3 Z
Does anyone have a suggestion?
Edited and will do in the future.
Try:
join -j1 -o1.1,2.2,1.2 -a1 <(sort file1) <(sort file2)
awk '{a[$1]=a[$1]FS$2}END{for(i in a)print i,a}' file2 file1 | awk 'NF < 3 {$3=FS$2;$2=FS}1'
# awk 'BEGIN{OFS=" "}NR==FNR{a[$1]=$2}NR>FNR{if($1 in a)print $1,a[$1],$2;else{$2=OFS" "$2;print}}' file2 file1
A 1 W
B X
C 2 Y
D 3 Z
regards
ygemici
Thank you greatly, I was not familiar with the join command.