Padding Empty Field in Unix Join Operation Padding Empty Field in Unix Join Operation unix unix

Padding Empty Field in Unix Join Operation


"Important: FILE1 and FILE2 must be sorted on the join fields." (from this online manpage).

This problem #1. Problem #2 is worse: option -e is badly documented -- only works in conjunction with -o, so for example:

$ join -a 1 -a 2 -e'-' -o '0,1.2,2.2' sfile1.txt sfile2.txtbar 2 -boo - zfoo 1 xqux 3 y

where the s prefix name indicated files that I've sorted beforehand.

Edit: man join explains the -o switch (so does the online manpage I point to above). It specifies the fields to output (1.2 means 2nd field from file 1, &c), or 0 to mean the join field, and is a comma-separated list. (I didn't remember the 0 value, actually, so had originally given a clumsier solution requiring awk post-processing, but the current solution is better... and no awk needed!).


-e only works with -o

join -a 1 -a 2 -e"-" -o auto file1.txt file2.txt