The middle part takes care to escape any regular expression special characters so you can pass them to grep. This is off the cuff so I probably forgot about one or two which would need escaping.
The search can be turned around to get the full lines from file1. I'm surprised your grep doesn't support the -f option, but that can be worked around with sed, too.
sed -e 's/[][\\.*^$]/\\&/g' -e 's%^%m^....................%' -e 's/$/%p' file2 | sed -nf - file1
You could create an awk script just as well as a sed script, but I already had the first half in sed, so it was easier to build on that.
awk '
NR==FNR{a[substr($0,1,11)];next} # Create an array of the key (position 1-11) in file2
substr($0,21,11) in a{print} # If position 21-31 of file1 exist in array print the record
' file2 file1
This link gives an explanation how to deal with errors in awk:
Another point of cleverness to note is "NR==FNR" which is true while processing the first line on the command line. Both are incremented when a new line is read, but FNR gets reset to zero when the file changes, while NR grows forever. And the "next" on that line means the following line of the script doesn't get executed while the condition is true; it causes awk to read the next line and start over.
If I want to add one more condition to the below while comparing.. can I modify as below =>
Old code
awk '
NR==FNR{a[substr($0,1,11)];next} # Create an array of the key (position 1-11) in file2
substr($0,21,11) in a{print} # If position 21-31 of file1 exist in array print the record
' file2 file1
New code
awk '
NR==FNR{a[substr($0,1,11)];next} # Create an array of the key (position 1-11) in file2
substr($0,21,11) | substr($0,41,11)in a{print} # If position (21-31) or (41 -51) of file1 exist in array print the record
' file2 file1