The purpose is to check if values for column 3 and 4 in file1 match with column 1 in file2.
If any value match do:
1) Replace values in file2 for column 2 and 3 using the information of file1 columns 5 and 6
2) Replace string ($1,1,5) and string ($1,6,5) in file2 with values of columns 7 and 8 from file1
3) Add character R for lines replaced and O for lines not replaced.
file1
2,100,31431,37131,999991.70,0000000.30,11111,22222,3
3,100,31431,37471,111113.20,1111111.30,22222,33333,4
file2
3143137113 318512.50 2334387.50 100
3143137131 318737.50 2334387.50 100
3143137201 319612.50 2334387.50 100
3143137471 322987.50 2334387.50 100
3143137491 323237.50 2334387.50 100
Desired output:
31431,37113,318512.50,2334387.50,100,O
11111,22222,999991.70,0000000.30,100,R
31431,37201,319612.50,2334387.50,100,O
22222,33333,111113.20,1111111.30,100,R
31431,37491,323237.50,2334387.50,100,O
I tried
awk -F, 'NR==FNR{a[$3 $4]=substr($0,length($3 FS)+1);next} $1 in a{print a[$1],$NF;next} {$1=substr($1,1,5) OFS substr($1,6,5);} 1' OFS=, file1 FS=' ' file2