I have a file test.txt on my linux system which has data in following format :
first second third fourth 10 first second third fourth 20 fifth sixth sevent
Reuse of my solution (J4F)
cat file.txt | sort | while read L; do y=`echo $L | rev | cut -f2- -d' ' | rev`; { test "$x" = "$y" && echo -n " `echo $L | awk '{print $NF}'`"; } || { x="$y";echo -en "\n$L"; }; done