-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveQuotes.py
More file actions
35 lines (30 loc) · 893 Bytes
/
removeQuotes.py
File metadata and controls
35 lines (30 loc) · 893 Bytes
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
#!/usr/bin/env python3
"""
removeQuotedText.py: remover text between quotes from text
usage: removeQuotedText.py < file.txt
20181127 erikt(at)xs4all.nl
"""
import re
import sys
QUOTE = "QUOTE"
OPENQUOTE = "„"
CLOSEQUOTE = '"'
UNSEENQUOTE = -1
def process(line):
if not re.search(OPENQUOTE,line) or not re.search(CLOSEQUOTE,line):
return(line)
words = line.split()
lastOpenQuote = UNSEENQUOTE
for i in range(0,len(words)):
if words[i] == OPENQUOTE: lastOpenQuote = i
elif words[i] == CLOSEQUOTE and lastOpenQuote != UNSEENQUOTE:
for j in range(lastOpenQuote+1,i): words[j] += QUOTE
lastOpenQuote = UNSEENQUOTE
line = " ".join(words)
return(line)
def main(argv):
for line in sys.stdin:
line = line.strip()
print(process(line))
if __name__ == "__main__":
sys.exit(main(sys.argv))