scripting - Bourne Shell compare two strings -
i need compare 2 string in bourne shell of same fixed length. need compare each character against place holder in opposite string , find out how many differences there are. have suggestions on how go this?
i after way of number of differences i.e. if compared aab & aac differences 1.
this has 100% bourne.
if don't mind creating temporary files, can use cmp method. bourne shell pretty limited can do. either use zsh/bash or if sh essential, write c program did want.
if creating files every time out of question, create fifos, hackish , ugly, don't it!
mkfifo cmp1 mkfifo cmp2 echo "abcd" > cmp1 & echo "abce" > cmp2 & diff_chars=`cmp -l cmp1 cmp2 | wc -l`
process substitution in bash or modern shell makes trivial , try use that.
Comments
Post a Comment