linux - merging two files based on two columns -
i have question similar previous post: merging 2 files single column in unix want merge data based on 2 columns (the orders same, no need sort). example,
subjectid subid2 name age
12 121 jane 16
24 241 kristen 90
15 151 clarke 78
23 231 joann 31
subjectid subid2 prob_disease
12 121 0.009
24 241 0.738
15 151 0.392
23 231 1.2e-5
and output like
subjectid subid2 prob_disease name age
12 121 0.009 jane 16
24 241 0.738 kristen 90
15 151 0.392 clarke 78
23 231 1.2e-5 joanna 31
when use join considers first column(subjectid) , repeats subid2 column. there way of doing join or other way please? thank
join command doesn't have option scan more 1 field joining criteria. hence, have add intelligence mix. assuming files has fixed number of fields on each line, can use this:
join f1 f2 | awk '{print $1" "$2" "$3" "$4" "$6}'
provided the field counts given in examples. otherwise, need adjust scope of print in awk command, adding or taking away fields.
Comments
Post a Comment