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
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
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 substring expansion to
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu'
-DCONF_VENDOR='redhat'
On Tuesday 6 May 2008 07:53, Nathan Coulter wrote:
Looking for a simple ways to output the byte at which two strings differ.
Here is one:
cmp (echo hello) (echo help) | cut -d' ' -f5 | tr -d ,
Any other suggestions?
I can't see how this pertains to gnu.bash.bug, however try this:
echo
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+1))
2008-05-06, 01:53(-04), Nathan Coulter:
Looking for a simple ways to output the byte at which two strings differ.
Here
is one:
cmp (echo hello) (echo help) | cut -d' ' -f5 | tr -d ,
Any other suggestions?
I'd suggest you fix the locale to being C for more portable
results.
LC_ALL=C cmp
Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale'
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
According to Herrmann, Justin on 5/6/2008 8:20 AM:
| Description: When I try to pass strings inside double or single quotes
| as command line arguments to my Bash script, leading spaces, trailing
| spaces, and multiple grouped embedded spaces are