Bash join command
Works for me (almost). You should specify -t $'\t'
for the tab character, not just -t \t
. Bash does not interpret \t
unless in $''
quotes.
join -t $'\t' -o 1.2,2.2 <(echo $'27\t2728\t2229\t3730\t1531\t2132\t1333\t1834\t24' | sort) <(echo $'27\t728\t1329\t630\t1231\t3032\t533\t1034\t28' | sort)27 722 1337 615 1221 3013 518 1024 28
First sort
both files. Then use join
to join on the first field of both files. You also need to pipe the output through sed
if you want to remove the space and thus convert a a
into aa
. This is shown below:
$ join -t " " -1 1 -2 1 -a 1 -a 2 <(sort file1) <(sort file2) | sed 's/ \([a-z]\) / \1/g'1 aa2 b3 c4 d5 e6 ff7 g8 h