-
Notifications
You must be signed in to change notification settings - Fork 1
/
multiplot
executable file
·72 lines (63 loc) · 1.19 KB
/
multiplot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
USAGE="usage: multiplot [list of node numbers or ranges]"
# usage: multiplot [list of node numbers or ranges]"
# example: "multiplot 1 3 6-9 < datafile | pd"
# a null list prints all the columns
# RCW: 11/17/2015
export NODES=$*
awk '
BEGIN {
nodes=ENVIRON["NODES"]
}
/^[ ]*[-+.0-9]/ {
lines++
nf = max(nf,NF);
for (i=1; i<=NF; i++) {
F[i,lines] = $i
}
next;
}
// {
print $0 # pass non numeric through
}
function max(a,b) {
if (a>b) return a
return b
}
END {
if (nodes=="") {
nnodes=nf
for (i=2; i<=nnodes; i++) {
for (j=1; j<=lines; j++) {
print F[1,j], F[i,j]
}
}
} else {
nnodes=split(expand(nodes),aa);
for (i=1; i<=nnodes; i++) {
for (j=1; j<=lines; j++) {
print F[1,j], F[aa[i],j]
}
}
}
}
function expand(rangelist, n, out, a, o, b) {
n=split(rangelist, a);
out=""
for(i=1; i<=n; i++) {
if(a[i] ~ /-/) {
m=split(a[i],b,"-")
if (m==2) {
for(o=b[1];o<=b[2];o++) {
out=out " " o
}
out=out " "
}
} else {
out=out " " a[i];
}
}
return out
}
'
exit 1