Use join
, include sort
if your data isn't sorted by the appropriate field.
join -1 2 -2 3 -o 2.3 <(sort -k2,2 file1) <(sort -k3,3 file2)
If sort
isn't needed:
join -1 2 -2 3 -o 2.3 file1 file2
This is using GNU utilities. For other variants I would need to know what Unix you're using. The version above with sort
is shown with Bash process substitution which also works in some other shells.
Since the join field is also the output field, -o 2.3
can be simplified to -o 0
.