summaryrefslogtreecommitdiff
path: root/src/pmdas/sample/get_next_pmid
blob: 5443a7d98b397be152f1c17b44be746a2b13bd3d (plain)
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
#!/bin/sh
#
# find next unallocated PMIDs for the sample PMDA
#

if [ $# -gt 1 ]
then
    echo "Usage: $0 [N]"
    echo "N defaults to 1 (PMID to generate)"
    exit 1
fi
want=1
[ $# -eq 1 ] && want="$1"

root=root
if [ ! -f $root ]
then
    root=../root
fi
if [ ! -f $root ]
then
    echo "Error: cannot find PMNS in root nor ../root"
    exit 1
fi

pminfo -m -n $root \
| sed -n -e '/ 29/s/\(.*\): \(.*\)/\2 \1/p' \
| sort -t . -n -k 1,1 -k 2,2 -k 3,3 \
| sed -e 's/ .*//' -e 's/\./ /g' \
| awk '
BEGIN	{ lastidx = -1; found = 0 }
NF != 3	{ next }
$2 != 0	{ next }
	{ if (lastidx+1 != $3) {
	    for (i = lastidx+1; i < $3; i++) {
		print "SAMPLE:0:" i
		found++
		if (found == '"$want"') exit
	    }
	  }
	  lastidx = $3
	}
END	{ while (found < '"$want"') {
	    lastidx++
	    print "SAMPLE:0:" lastidx
	    found++
	  }
	}'