Linux bash command that returns where two strings differ -



Linux bash command that returns where two strings differ -

so, i've been googling around, , searching in more detail on stack overflow, can't seem find easy way of doing this:

i want know in way 2 strings (without whitespace) differ, , print exact difference is.

e.g.:

input 1 > "chocolatecakeflavour" input 2 > "chocolateflavour" output: "cake"

i've tried doing diff , dwdiff, cmp, , other known bash commands popped mind, couldn't exact result.

any ideas?

you can utilize diff fold , awk ths:

s="chocolatecakeflavour" r="chocolateflavour" diff <(fold -w1 <<< "$s") <(fold -w1 <<< "$r") | awk '/[<>]/{printf $2}' cake fold -w1 split input string character character (one in each line) diff difference in both lists (1 char in each line) awk '/[<>]/{printf $2}' suppress < or > diff'e output , print in same line

edit: per op's comments below if strings in different lines of file use:

f=file diff <(fold -w1 <(sed '2q;d' $f)) <(fold -w1 <(sed '3q;d' $f)) | awk '/[<>]/{printf $2}' cake

linux string bash command-line difference

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -