Re: finding the index at which two strings differ

2008-05-07 Thread Dave B
On Tuesday 6 May 2008 22:33, Dave B wrote: > while [ $i -le $((${#a}-1)) ] && [ $i -le $((${#b}-1)) ]; do while [ $i -lt ${#a} ] && [ $i -lt ${#b} ]; do -- D.

Re: finding the index at which two strings differ

2008-05-06 Thread Dave B
On Tuesday 6 May 2008 21:29, Bob Proulx wrote: > I can't think of any way to do this natively in bash Well, there's a loop solution, but it's a bit awkward: a=help; b=hello; i=0 while [ $i -le $((${#a}-1)) ] && [ $i -le $((${#b}-1)) ]; do if [ "${a:${i}:1}" = "${b:${i}:1}" ]; then i=$((i+

Re: finding the index at which two strings differ

2008-05-06 Thread Mike Stroyan
On Tue, May 06, 2008 at 01:29:13PM -0600, Bob Proulx wrote: > 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? You could use subs

Re: finding the index at which two strings differ

2008-05-06 Thread Bob Proulx
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 conce

finding the index at which two strings differ

2008-05-06 Thread Poor Yorick
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? -- Yorick