From 2f195ac53062e085a050c8c42615a4e7ca07ecd8 Mon Sep 17 00:00:00 2001 From: TKE Date: Thu, 25 Mar 2021 18:13:35 +0100 Subject: [PATCH] add preserve-switch to kv_parse --- kv_parse.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kv_parse.py b/kv_parse.py index 85c89a8..57465a2 100755 --- a/kv_parse.py +++ b/kv_parse.py @@ -5,6 +5,7 @@ import argparse import sys parser = argparse.ArgumentParser() +parser.add_argument("-p", "--preserve", action='store_true', help="preserve original logline in dict") parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin) parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), default=sys.stdout) args = parser.parse_args() @@ -20,8 +21,8 @@ for line in data: matches=kv_pat.findall(line) for match in matches: line_dict[match[0]] = match[1].strip('"') + if args.preserve: + line_dict['original_logline'] = line log.append(line_dict) -json.dump(log,args.outfile) - - +json.dump(log,args.outfile) \ No newline at end of file