4

I have a 2 files with the following:

File1.txt 
A 1
B 2
C 5
Z 3

File2.txt
A 4
B 7 
C 10
D 11

What I would like to do is create something like

A 1 4 
B 2 7
C 5 10
D - 11
Z 3 -

Is there a utility that does this? If not how Can this be done? Using a find and awk or something?

8
join -a1 -a2 -o 0,1.2,2.2 -e - file1.txt file2.txt
  • Does This require that the files be sorted in order? – Sten Kin Aug 4 '14 at 17:18
  • @StenKin, yes, the inputs must be sorted on the join keys (here the first column). – Stéphane Chazelas Aug 4 '14 at 20:00
0
$ join File1.txt File2.txt

almost does what you want - but it only displays lines which have a matching key.

It's easy enough to script the result you want, but I don't know a single utility that does it exactly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.