Mercurial > hg > cc > azure
comparison master/src/wecu/sac_mapper.py @ 58:a3edba8dab11
move to right place in tree
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Thu, 28 May 2020 09:56:42 +0000 |
parents | master/wecu/sac_mapper.py@ac1a20e627a9 |
children | 5fdca5baa4e9 |
comparison
equal
deleted
inserted
replaced
57:ac1a20e627a9 | 58:a3edba8dab11 |
---|---|
1 #!/usr/bin/python3 | |
2 import os | |
3 import sys | |
4 import re | |
5 | |
6 is_regex = sys.argv[1] == 'true' | |
7 search_terms = sys.argv[2:] | |
8 search_terms_counters = dict() | |
9 | |
10 # Initialise | |
11 for term in search_terms: | |
12 search_terms_counters[term] = 0 | |
13 | |
14 if not is_regex: | |
15 for line in sys.stdin: | |
16 for term in search_terms_counters: | |
17 search_terms_counters[term] += line.count(term) | |
18 else: | |
19 for line in sys.stdin: | |
20 for term_regex in search_terms_counters: | |
21 search_terms_counters[term_regex] += len(re.findall(term_regex, line)) | |
22 | |
23 | |
24 for term in search_terms_counters: | |
25 print("{}\t{}".format(term, search_terms_counters[term])) |