0

I have 2 file:

file1

SC  65.696  618
SC  61.92   625
KN  82.546  1037
KN  82.946  1032
KN  82.849  1032
CN  70.55   618

and

file2

SC  SC7  SCARE      588     2       75702
KN  KN4  Kines     1033     2   1   3635
CN  CNGC Prote      703     2       3880

need to join, according to column 1 and with repeated rows

file3

SC  65.696  618     SC  SC7     SCARE   588     2       75702
SC  61.92   625     SC  SC8     SCARE   588     2       75703
KN  82.546  1037    KN  KN4     Kines   1033    2   1   3635
KN  82.946  1032    KN  KN5     Kines   1033    2   1   3636
KN  82.849  1032    KN  KN6     Kines   1033    2   1   3637
CN  70.55   618     CN  CNGC    Prote   703     2       3880


Thank you in advance,

1
  • Hi again, the problem is sixth column of file two, which some rows were empty. so after joining, this column were merged by seventh column,
    – Poursa
    Commented Jul 19, 2019 at 11:51

1 Answer 1

1

This is the default behavior of join:

$ join <(sort file1) <(sort file2)
CN 70.55 618 CNGC Prote 703 2 3880
KN 82.546 1037 KN4 Kines 1033 2 1 3635
KN 82.849 1032 KN4 Kines 1033 2 1 3635
KN 82.946 1032 KN4 Kines 1033 2 1 3635
SC 61.92 625 SC7 SCARE 588 2 75702
SC 65.696 618 SC7 SCARE 588 2 75702
5
  • 2
    Note that for join to work properly, the input data files needs to be sorted on the join field (the 1st column in this case).
    – Kusalananda
    Commented Jul 19, 2019 at 8:59
  • 1
    thanks, updated
    – pLumo
    Commented Jul 19, 2019 at 9:00
  • 1
    It happened to work without sorting this time, probably because the files had the same ordering. But in the general case...
    – Kusalananda
    Commented Jul 19, 2019 at 9:08
  • Oh, thank you all and sorry, I had searched before and not find anything useful. anyway, I should look better. thanks again
    – Poursa
    Commented Jul 19, 2019 at 9:45
  • To join on a field other than the first, use `-j
    – user234461
    Commented Jul 19, 2019 at 11:02

Not the answer you're looking for? Browse other questions tagged .