File: transpose.awk

package info (click to toggle)
stx-btree 0.8.3-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,948 kB
  • ctags: 6,441
  • sloc: cpp: 6,251; sh: 3,674; makefile: 161; awk: 16; xml: 9
file content (23 lines) | stat: -rwxr-xr-x 300 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/gawk -f
# Transpose a matrix: assumes all lines have same number
# of fields

NR == 1 {
    n = NF
    for (i = 2; i <= NF; i++)
	row[i] = $i
    next
}

{
    if (NF > n)
	n = NF
    for (i = 2; i <= NF; i++)
	row[i] = row[i] " " $i
}

END {
    for (i = 2; i <= n; i++)
	print row[i]
}