grouping records in a file in unix

I have file like this

d123, rahim, 140
d123, rahul, 440
d123, begum, 340
d234, bajaj, 755
d234, gajal, 657

I want to group this file like this

d123, rahim, 140
      rahul, 440
      begum, 340
d234, bajaj, 755
      gajal, 657

can any one help me on this

thanks in advance

deleted.
misunderstood the problem.

I havent run the following, but I think it will work...

for i in `cat file | cut -d"," -f1`
do
grep $i file >> temp
head -1 temp >> result
count_line=`wc -l temp`
count=`echo $count_line | tr -s " " " " |cut -d" " -f1`
if [ $count -gt 1 ]
then
count=` expr $count - 1 `
tail -$count temp | cut -c6- >> result
fi
rm temp
done

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 11:29 AM ---------- Previous update was at 11:13 AM ----------
assuming the file sorted based on the FIRST column...

nawk '
   BEGIN {
     FS=OFS=", "
   }
   prev==$1 {
      sub("^[^,]*,",sprintf("%*c", length($1)+1, " "))
      print; next
   }
   {print;prev=$1}' myFile

hi
i tried the approach and it is working

Try this:

awk -F, '$1 != s{s=$1;print;next}{print "     " $2 FS $3}' file

Regards

hi
thanks for your help
the solution you gave was working
can you plz. explain me how it is working

And if input file is not sorted on first column:

BEGIN{FS=", ";ORS=""}
{
	_[$1]=_[$1]?
	sprintf("%s  %*s, %s\n",_[$1],length($1)+length($2),$2,$3):
	sprintf("%s, %s, %s\n",$1,$2,$3)
}
END{for(i in _) print _} 

To whom is the request addressed?