ram="rambo"
ram1="rimbo"
awk -v ram=$ram -v ram1=$ram1 '{ for (i=1;i<=length(ram);i++) { if (substr(ram,i,1) != substr(ram1,i,1)) { count++ } }} END { print (count/length(ram)*100"% difference") }' <<< ""
output:
20% difference
The above example assumed that bithboth variables ram and ram1 are always the same size in length. We pass both variables to awk and check each character one by one against the one in the other string, tracking the differences with a count variable.
At the end, we work out the percentage of the string that is different.