Poor Yorick wrote:
> Looking for a simple ways to output the index at which two strings
> differ. Here is one:
>
> cmp <(echo "hello") <(echo "help") | cut -d' ' -f5 | tr -d ,
>
> Any other suggestions?
That seems reasonable to me. Although I tend to use awk and sed for
such things. The concept is basically the same as your suggestion
with one less pipe of character I/O.
awk '{gsub(/,/,"");print$5}'
sed 's/.*byte \([[:digit:]][[:digit:]]*\),.*/\1/'
I can't think of any way to do this natively in bash. I can't think
of a better tool than cmp to do this comparison. But perhaps someone
else more clever than I will have a more elegant solution.
Bob