-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.controls.iof2.awk
56 lines (53 loc) · 1.3 KB
/
get.controls.iof2.awk
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
# get.controls.iof2.awk
# use getXML.awk parser
# parseroi IOF 2.0.3 mukaisen tiedoston
# gawk -f get.data.awk radat.xml | awk -f get.controls.iof2.awk
function print_course(Variant,Controls,Codes) {
printf "%s%s%d%s0-%s%s",Variant,OFS,Controls,OFS,Codes[1],OFS
Prevcode=Codes[1]
for (r=2;r<=Controls;r++) {
printf "%s-%s%s",Prevcode,Codes[r],OFS
Prevcode=Codes[r]
}
printf "%s-M",Prevcode
print ""
}
BEGIN { FS="|"
OFS="|"
maxcontrols=99
controlcnt=0
}
#$1 == "DAT" && $2 == "CourseName" && length($NF) > 0 {
# on DAT, elementin nimi haluttu ja elementin polku haluttu - testataan loppu
# tuo polkutesti paljastaa onko elelemtti rivi vai sulkeva rivi, jolloin polussa ei ole elementin rivia
$1 == "DAT" && $2 == "CourseName" && $3 ~ /CourseName$/ {
if (controlcnt>0) { # edellinen rata ulos
print_course(coursename,controlcnt,codes)
}
#print $2,$NF
course=0
controlnum=0
coursename=$NF
for (r=1;r<=maxcontrols;r++) {
codes[r]=""
}
controlcnt=0
next
}
$1 == "DAT" && $2 == "Sequence" && $3 ~ /Sequence$/ {
#print $2,$NF
controlnum=$NF
controlcnt++
next
}
$1 == "DAT" && $2 == "ControlCode" && $3 ~ /ControlCode$/ {
#print $2,$NF
codes[controlnum]=$NF
next
}
END {
#
if (controlcnt>0) { # last course
print_course(coursename,controlcnt,codes)
}
}