Skip to main content
new example input
Source Link
chaos
  • 49.4k
  • 11
  • 128
  • 147

A classic with join:

join -t: -1 12 -2 21 -o 2.1,1.1,1.2 <(sort -t: -k1,1 file1) <(sort -t: -k2,2 file2) 
  • -t: specifies the colon as separator.
  • -1 12 file1's join field is the firstsecond one
  • -2 21 file2's join field is the secondfirst one
  • -o 2.1,1.1,1.2 the output format.
  • <(...): both files must be sorted on the join field (-k1,1 and -k2,2), -t: specifies the colon as separator for sort.

A classic with join:

join -t: -1 1 -2 2 -o 2.1,1.1,1.2 <(sort -t: -k1,1 file1) <(sort -t: -k2,2 file2) 
  • -t: specifies the colon as separator.
  • -1 1 file1's join field is the first one
  • -2 2 file2's join field is the second one
  • -o 2.1,1.1,1.2 the output format.
  • <(...): both files must be sorted on the join field (-k1,1 and -k2,2), -t: specifies the colon as separator for sort.

A classic with join:

join -t: -1 2 -2 1 -o 2.1,1.1,1.2 <(sort -t: -k1,1 file1) <(sort -t: -k2,2 file2) 
  • -t: specifies the colon as separator.
  • -1 2 file1's join field is the second one
  • -2 1 file2's join field is the first one
  • -o 2.1,1.1,1.2 the output format.
  • <(...): both files must be sorted on the join field (-k1,1 and -k2,2), -t: specifies the colon as separator for sort.
Source Link
chaos
  • 49.4k
  • 11
  • 128
  • 147

A classic with join:

join -t: -1 1 -2 2 -o 2.1,1.1,1.2 <(sort -t: -k1,1 file1) <(sort -t: -k2,2 file2) 
  • -t: specifies the colon as separator.
  • -1 1 file1's join field is the first one
  • -2 2 file2's join field is the second one
  • -o 2.1,1.1,1.2 the output format.
  • <(...): both files must be sorted on the join field (-k1,1 and -k2,2), -t: specifies the colon as separator for sort.