-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverparse.awk
115 lines (98 loc) · 2.09 KB
/
coverparse.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
BEGIN {
state = "find_name"
}
state == "find_name" && NF > 0 {
name = $0
state = "find_street"
next
}
state == "find_street" {
street = $0
state = "find_city"
next
}
state == "find_city" {
city = $0
state = "find_phone"
next
}
state == "find_phone" {
phone = $0
state = "find_email"
next
}
state == "find_email" {
email = $0
state = "find_date"
next
}
state == "find_date" && NF > 0 {
date = $0
state = "find_recipient_name"
next
}
state == "find_recipient_name" && NF > 0 {
recipient_name = $0
state = "find_recipient_company"
next
}
state == "find_recipient_company" {
recipient_company = $0
state = "find_recipient_street"
next
}
state == "find_recipient_street" {
recipient_street = $0
state = "find_recipient_city"
next
}
state == "find_recipient_city" {
recipient_city = $0
state = "find_opening"
next
}
state == "find_opening" && NF > 0 {
opening = $0
state = "find_body"
next
}
state == "find_body" && NF > 0 {
body = $0
state = "find_remaining_body"
next
}
state == "find_remaining_body" && /,$/ {
# If the line ends in a comma, this is likely the letter closing
state = "find_closing"
}
state == "find_remaining_body" {
# Concatenate lines of the letter body
body = body "\\n" $0
}
state == "find_closing" {
closing = $0
state = "find_sender_name"
next
}
state == "find_sender_name" && NF > 0 {
sender_name = $0
next
}
END {
printf "{\n"
printf " \"name\": \"%s\",\n", name
printf " \"street\": \"%s\",\n", street
printf " \"city\": \"%s\",\n", city
printf " \"phone\": \"%s\",\n", phone
printf " \"email\": \"%s\",\n", email
printf " \"date\": \"%s\",\n", date
printf " \"recipient_name\": \"%s\",\n", recipient_name
printf " \"recipient_company\": \"%s\",\n", recipient_company
printf " \"recipient_street\": \"%s\",\n", recipient_street
printf " \"recipient_city\": \"%s\",\n", recipient_city
printf " \"opening\": \"%s\",\n", opening
printf " \"body\": \"%s\",\n", body
printf " \"closing\": \"%s\",\n", closing
printf " \"sender_name\": \"%s\"\n", sender_name
printf "}\n"
}