1
file1 :

HOUSAM1189870            3      0.00   0  -2450.00  11
HOUSAM1213135            3      0.00   0  -2620.00   2
HOCANM245675             3      0.00   0      0.00   0
HOUSAM1239242            3      0.00   0  -3113.00   8

file2 :

AY840F3001138842 20050301
AY840F3001140253 20060101
HOCANM245675     34409887        
HOUSAM1239242    34444444

I want to join file1 and file2 based on common rows of their first column. therefore the output should be:

file3:

HOCANM245675             3      0.00   0      0.00   0 34409887
HOUSAM1239242            3      0.00   0  -3113.00   8 34444444

any suggestion, please ?

1 Answer 1

0

(note: this answer was written before the question was updated with the join command and the error messages)

the command is called join.

from the man page:

join - join lines of two files on a common field

since your input files are not sorted you need to sort them first

join <(sort file1) <(sort file2)

the <(...) things are called process substitution and is supported by bash and some other shells. if you have a shell that does not support process substitution then you have to work with intermediate files.

join is part of the gnu coreutils so it should be installed on most common gnu/linux systems.

4
  • i tried it but it does nit work
    – zara
    Commented Nov 16, 2016 at 19:53
  • does it help when you sort the files first? please explain how it does not work. please update the question with the relevant information.
    – Lesmana
    Commented Nov 16, 2016 at 19:55
  • problem is that when I use this command on my real data I have this error all the time :join: file 2 is not in sorted order join: file 1 is not in sorted order do you know why is that? I should not recive this error as I already sorted them
    – zara
    Commented Nov 16, 2016 at 20:05
  • your first file is not sorted. i tried join with (sorted) files in your updated question and everything worked fine. perhaps the size of the files is the problem?
    – Lesmana
    Commented Nov 16, 2016 at 20:24

You must log in to answer this question.

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