Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert to a matrix format 2

Status
Not open for further replies.

mguha06

Technical User
Apr 20, 2006
28
0
0
US
Hello,

Can anyone help me out to write an output in matrix format in AWK95, where my input file is in the form of, example:

2,3,1,0,A,0,1,42
2,4,1,0,B,0,1,42
3,1,1,0,C,0,1,42
3,2,1,0,D,0,1,42
3,3,1,0,E,0,1,42
4,6,1,0,F,0,1,42
4,7,1,0,G,0,1,42

My output file would be in the form:

A B
C D
F G


The first column in input file is row number and the second number is the column number and the result is 5th column.
Using the row and column number, placing the value from the 5th column in the output file. So you can see the value of A is placed in the 2nd row and 3rd column, similarly the value of B is placed in the 2nd row and 4th column. The value of F is in 4th row and 6th column, etc,

If anyone can help me with this it will be a tremendous help and would greatly acknowledge your help with many stars..

Thanks.
 
Hi

Code:
BEGIN {
  FS=","
}
{
  m[$1,$2]=$5
  if (r<$1) r=$1
  if (c<$2) c=$2
}
END {
  for (i=1;i<=r;i++) {
    for (j=1;j<=c;j++) printf "%1s ",m[i,j]
    print ""
  }
}
Code:
[blue]C:\>[/blue] awk95 -f mguha06.awk \input\file

    A B
C D E
          F G

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top