I am looking for a way to highlight the differences between two lines. The idea is to show in the terminal which characters iconv has changed. Both lines have already been processed to remove leading and trailing spaces, but internal spaces need to be handled.
RED="$(tput setaf 1)"
CYA="$(tput setaf 6)"
CLS="$(tput sgr0)"
str1="[String nâmè™]"
str2="[String name[tm]]"
Ultimately, I want to automate the formatting of the differences so that they are surrounded by tput color codes that I can repeat on the terminal.
${str1}= Highlight in red characters that are not common to both lines
${str2}= Highlight blue characters that are not common to both lines
Required Conclusion:
output1="[String n${RED}â${CLS}m${RED}è™${CLS}]"
output2="[String n${CYA}a${CLS}m${CYA}e[tm]${CLS}]"
Most diff utilities I looked at work on line or word level. I was thinking about parsing cmp output for byte # of the first diff, but I would have to re-parse for a few differences. It seems.
, , , , , .
, - , , .
nstr1="$(fold -w1 <<< "$(echo "${str1}")")"
nstr2="$(fold -w1 <<< "$(echo "${str2}")")"
diff <(echo -e "${nstr1}") <(echo -e "${nstr2}")
, , . , , ?