File: transpose.awk

package info (click to toggle)
stx-btree 0.9-1.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,104 kB
  • ctags: 8,163
  • sloc: cpp: 7,496; sh: 3,964; ansic: 235; perl: 104; makefile: 100; 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]
}