I'm trying to join two files each of which contains rows of the form <key> <count>. Each file contains a few lines that are missing from the other, and I would like to have zero inserted for all such values rather than omitting these lines (I've seen -a, but this isn't quite what I'm looking for). Is there a simple way to accomplish this?
Here is some sample input:
a.txt
apple 5
banana 7
b.txt
apple 6
cherry 4
expected output:
apple 5 6
banana 7 0
cherry 0 4
                join -o 0,1.2,2.2 -e 0 -a1 -a2 a.txt b.txt
-o 0,1.2,2.2 → output join field, then 2nd field of 1st file, then 2nd field of 2nd file.-e 0 → Output 0 on empty input fields.-a1 -a2 → Show all values from file 1 and file 2.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With