-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim.awk
executable file
·70 lines (63 loc) · 1.32 KB
/
sim.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/env /usr/bin/awk
# run this program
# awk -f sim.awk sim
#
# ouput formatting program
BEGIN {
# print("===================")
# print("TOTAL arguments : ", ARGC)
# printvector(ARGV)
# print("===================")
}
function printvector(vec) {
printf("Contents : \n")
for(i in vec)
printf(i "=>" vec[i]"<=>\n")
#print("")
}
{
#print(NR)
#a[NR-1] = "hello"
#a[$1]
#a[$1] = "Hello"
#a[$1] = $2" "$3
len = split($3, b, ",")
#print(len)
#print(len, b[1], b[2], b[3])
for(i=1; i<=len; i++) {
#print(b[i])
if(b[i] in a) {
a[b[i]] = a[b[i]]";"$2","$1
}
else {
a[b[i]] = $2","$1
}
}
#printvector(a)
# for(i in b)
# print(b[i], " ")
# if(1 in a)
# print("YES")
# else
# print("NO")
}
END {
#print(NR)
#for(i=0; i<NR; i++)
for(i in a) {
print(i":")
split(a[i], b, ";")
for(j in b) {
#print("\t"b[j])
split(b[j], splitb, ",")
res[splitb[2]] = b[j]
}
#printvector(res)
n = asorti(res, sortres)
#printvector(sortres)
for(ii=1; ii<=n; ii++)
print(ii"\t"res[sortres[ii]])
delete res
delete sortres
}
}