awk - Rotating an array 90 degrees

Hi All,

I have some data (below) that I need to rotate 90 degrees - in other words I want to flip each row into a column.

I've found the following code in the book "Effective awk programming" but it doesn't work on my input data. I've used arrays before but I can't make it work... can anyone help me out with this one? :slight_smile:

awk '{
                if (max_nf < NF)
                    max_nf NF
                max_nr = NR
                for (x = 1; x <= NF; x++)
                    vector[x, NR] = $x
} END {
      for (x = 1; x <= max_nf; x++) {
          for (y = max_nr; y >= 1; --y)
              printf("%s ", vector[x, y])
          print("\n")
      }
}' $1

Thanks in advance :slight_smile:

BTW: I've actually removed a text field from $1 (column 1) because I thought it would make it easier to solve - does this make any difference?

Cheers, p.

I've spotted a typo in my translation; correct code should read:

This now works but I'd like to find a solution that works on my input file that includes the text column in $1...

Correction again - I must've done something wrong before; the above code works perfectly at converting rows into columns :slight_smile: hurrah!

Congrats man!!!:b: