Join all the lines matching similar pattern

I am trying to Join all the lines matching similar pattern.
Example ;
I wanted to join all the lines which has sam to a single line.
In next line, i wanted to have all the lines with jones to a single line....etc

> cat sample.txt
sam 2012/11/23
sam 2012/12/5
sam 2012/12/5
jones 2012/10/16
jones 2012/10/17
jones 2012/10/17
mike 2012/11/24
mike 2012/12/25
mike 2012/12/25
mike 2012/12/25
mike 2012/12/25
mike 2012/12/25

I have tried the following command and however it is joining all the lines. Perhaps, i want to join the lines matching similar pattern.

> sed -e :a -e '$!N;s/\n'$line'/ '$line'/;ta' -e 'P;D' sample.txt
sam 2012/11/23 sam 2012/12/5 sam 2012/12/5 jones 2012/10/16 jones 2012/10/17 jones 2012/10/17 mike 2012/11/24 mike 2012/12/25 mike 2012/12/25 mike 2012/12/25 mike 2012/12/25 mike 2012/12/25

Thanks in Advance. :):o:b:

try:

awk '{a[$1]=$0" "a[$1]}; END {for (i in a) print a}' sample.txt
1 Like

Thanks a lot and it is working Great....