Mercurial > hg > cc > azure
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/master/src/wecu/sac_mapper.py Thu May 28 09:56:42 2020 +0000 @@ -0,0 +1,25 @@ +#!/usr/bin/python3 +import os +import sys +import re + +is_regex = sys.argv[1] == 'true' +search_terms = sys.argv[2:] +search_terms_counters = dict() + +# Initialise +for term in search_terms: + search_terms_counters[term] = 0 + +if not is_regex: + for line in sys.stdin: + for term in search_terms_counters: + search_terms_counters[term] += line.count(term) +else: + for line in sys.stdin: + for term_regex in search_terms_counters: + search_terms_counters[term_regex] += len(re.findall(term_regex, line)) + + +for term in search_terms_counters: + print("{}\t{}".format(term, search_terms_counters[term]))