how to convert columns to rows

Hi,
I need a shell script for below requirement

Input file
P1 - 173310
P2 - 173476
P3 - 173230
P4 - 172737
P1 - 173546
P2 - 173765
P3 - 173876
P4 - 172989

Out put file
P1 173310 173546
P2 173476 173765
P3 173230 173876
P4 172737 172989

Suresh

Use nawk or /usr/xpg4/bin/awk on Solaris:

awk -F' *- *' 'END { 
  while (++i <= c) print order, row[order]
  }
{
  row[$1] = row[$1] ? row[$1] OFS $2 : $2
  while (!temp[$1]++) order[++c] = $1   
  }' infile 

Thank u very much. Its working..........

One way with awk:

awk '
{a[$1]=a[$1]?a[$1]FS$3:$1FS$3}
END{for(i in a) print a}
' file

Regards

Maybe but that is called double posting and against the rules!

Removed the second one.

Hi All,

Both the scripts working.. Thank u all