bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: at which byte do two strings differ


From: Dave B
Subject: Re: at which byte do two strings differ
Date: Tue, 06 May 2008 11:23:09 +0200

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 'hello help' | sed 's/\([^ ]*\)[^ ]* \1.*/\1/' | wc -m

(this exploits the fact that a newline is appended at the end, so wc sees an
additional character, and gives the expected result).

If the strings can have spaces in them, then use a different separator.

-- 
D.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]