first file Format pos start end id chr1 11223 11224 rs2342349 chr2 23423 23424 rs6345435 chr3 64564 64565 rs3432456 chr4 56456 56457 rs7979979 second file Format id rs2342349 #only match rs3274234 rs2342344 Output1 chr1 11223 11224 rs2342349 Output2 Number_pos_1st_file 4 Number_pos_2nd_file 3 Nr_Matching 1 Nr_Non_matching 2