-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.awk
executable file
·51 lines (37 loc) · 1.02 KB
/
events.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
#!/usr/bin/awk -f
# Project: Reappropriation
# Author: Karandeep Singh Nagra
# Process events files. Create a Python dictionary for each entry.
# To call this script, execute:
# ./events.awk ../all_events.txt > events_r.txt
# Set the field separator to the tab character
# This will make the fields:
# $2 := date of event
# $3 := title of event
# $4 := event description
# possibly $(>=5) := extra lines of the body
BEGIN {
FS = "\t"
}
{
# Section head
if (match($0, /^@@@/)) {
++section_number
next
}
if (match($0, /^$/)) {
next
}
gsub(/^# */, "", $0)
gsub(/</, "\<", $0)
gsub(/"/, "\"", $0)
# For whatever reason, tabs in the fourth entry also represent newlines.
# So, append all entries after the fourth, separated by newline characters.
if (NF > 3) {
for (i = 4; i <= NF; ++i) {
$3 = $3 "<br />" $i
}
}
gsub(/<br \/>$/, "", $0)
print "{'date': \"" $1 "\", 'title': \"" $2 "\", 'description': \"" $3 "\"}"
}