-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathexolve-to-plain.sh
53 lines (48 loc) · 996 Bytes
/
exolve-to-plain.sh
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
#!/bin/bash
awk_script='
BEGIN {
in_grid = 0;
in_clues = 0;
} /exolve/ {
in_grid = 0;
in_clues = 0;
} /exolve-grid/ {
in_grid = 1;
in_clues = 0;
} /exolve-across/ {
in_grid = 0;
in_clues = 1;
printf "\nAcross:\n";
} /exolve-down/ {
if (in_grid) printf "\n";
in_grid = 0;
in_clues = 1;
printf "Down:\n";
} !/exolve-/ {
if (in_grid) {
gridline = $0;
gsub(/ /, "", gridline);
gsub(/\./, "=", gridline);
printf "%s\n", gridline;
}
if (in_clues) {
clue = $0;
# Code to...
num_matches = match(clue, /[0-9]+/);
if (num_matches != 0) {
num = substr(clue, RSTART, RLENGTH);
printf "%4d. ", num;
clue = substr(clue, RSTART + RLENGTH);
}
num_matches = match(clue, /) \[[A-Z]/);
if (num_matches != 0) {
clue = substr(clue, 1, RSTART);
}
gsub(/~{/, "", clue);
gsub(/}~/, "", clue);
gsub(/^[ ]+/, "", clue);
gsub(/[ ]+$/, "", clue);
printf "%s\n", clue;
}
}'
awk "$awk_script" -