join omitting output lines when input sorted numerically join omitting output lines when input sorted numerically unix unix

join omitting output lines when input sorted numerically


Use a lexicographical sort rather than a numeric sort.

To do this as part of the process:

$ join <(sort aa) <(sort bb)

This gives the output:

10101 sdf 2223210301 23 llll84 xxx asdfasdf


You failed to include the fact that an error message is output:

$ join aa bbjoin: file 2 is not in sorted order84 xxx asdfasdfjoin: file 1 is not in sorted order

You can use a normal lexicographic sort:

join <(sort aa) <(sort bb) | sort -k1,1n


If you want to avoid sorting, then you can zero pad with awk:

join \ <(awk '{printf("%05d %s\n", $1, $2)}' aa) \ <(awk '{printf("%05d %s\n", $1, $2)}' bb) \| awk '{print int($1),$2,$3}'

Generates this output that preserves the original sort order:

84 xxx asdfasdf10101 sdf 2223210301 23 llll

You want to avoid sort, because Unix sort is O(n log n).