-
Notifications
You must be signed in to change notification settings - Fork 0
/
findScripts.groovy
41 lines (35 loc) · 1.01 KB
/
findScripts.groovy
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
// Copyright (c) 2011-2019 Egon Willighagen <[email protected]>
//
// GPL v3
// find all references to scripts
//
// it takes one optional argument, which is appended to the output
if (args.length == 0) {
println "groovy findScripts.groovy <directory> [suffix]"
System.exit(0)
}
def folder = args[0]
def suffix = ""
if (args.length == 2) suffix = args[1]
def basedir = new File(folder)
files = basedir.listFiles().grep(~/.*i.md$/)
files.each { file ->
file.eachLine { line ->
try {
if (line.contains("<sparql>")) {
start = line.indexOf("<sparql>")
end = line.indexOf("</sparql>")
text = line.substring(start + 8, end)
println "" + text + suffix
} else if (line.contains("<out>")) {
start = line.indexOf("<out>")
end = line.indexOf("</out>")
text = line.substring(start + 5, end)
println "" + text + suffix
}
} catch (Exception exception) {
println "Error reading line: " + line
System.exit(-1)
}
}
}