Comparing strings with sed

Input:

The the
the the

Output:

not-same
same

What would be the sed command to do this?

This would be one possibility:

sed -n 'N;/^\(.*\)\n\1$/!{s/$/\nnot-same/p}' infile

I have edited the output.

awk '{print ($1==$2)?"same":"not-same"}' urfile

Hi

# sed -e '/\(.*\) \1$/!s/.*/not same/' -e 's/\(.*\) \1$/same/'  file
not same
same
#

Guru.

another way:

sed '/\(.*\) \1$/{ s/.*/same/; b; }; s/.*/not-same/;' file

with spaces and tabs

# cat infile
The the
the the
THE THE
THE    THE
THE             THE
THE         THE
the THE
the     the
the            the
THE     THE
THE                     THE
THE     THE
THE     NOT
 
# sed '/\([^ ]*\)[\t ] *[\t]*\1$/!s/.*/notsame/;s/\([^ ]*\)[\t ] *[\t]*\1$/same/' infile
notsame
same
same
same
same
same
notsame
same
same
same
same
same
notsame
sed '/\(.*\)[[:blank:]]\+\1$/{ s/.*/same/; b; }; s/.*/not-same/;' file