tweak of two files
Solution 1:
You can split the first field on .
and use only the first element as your associative array key. Given:
$ head file{1,2}
==> file1 <==
string1.str1.co.in,ZSER
string2.str2.com,ABCD
string3.str.co.in,ZSE
string4.str2.com,ACD
==> file2 <==
string1.str1.co.in, [A], hello1, hello2
string2.str2.com, 2nd, hello
string3, 3rd, helloz
string4, 4th, hellox
string5, 5th, helloo
string5, 6th, helloop
then
$ awk '
BEGIN {OFS=FS=","}
split($1,b,".") {key = b[1]}
NR==FNR {a[key] = $2; next}
(key in a) {$1 = $1 OFS a[key]}
1
' file1 file2
string1.str1.co.in,ZSER, [A], hello1, hello2
string2.str2.com,ABCD, 2nd, hello
string3,ZSE, 3rd, helloz
string4,ACD, 4th, hellox
string5, 5th, helloo
string5, 6th, helloop
If you want to output a blank or other string in non matching cases you can change the last pattern-action pair from (key in a) {$1 = $1 OFS a[key]}
to {$1 = (key in a) ? $1 OFS a[key] : $1 OFS " "}
:
$ awk '
BEGIN {OFS=FS=","}
split($1,b,".") {key = b[1]}
NR==FNR {a[key] = $2; next}
{$1 = (key in a) ? $1 OFS a[key] : $1 OFS " "}
1
' file1 file2
string1.str1.co.in,ZSER, [A], hello1, hello2
string2.str2.com,ABCD, 2nd, hello
string3,ZSE, 3rd, helloz
string4,ACD, 4th, hellox
string5, , 5th, helloo
string5, , 6th, helloop