Improve log_cleaner
This commit is contained in:
parent
c47fb53c10
commit
3589295e22
@ -3,7 +3,7 @@
|
||||
# 22/03/2022
|
||||
# tool script used to remove unwanted lines from log files
|
||||
#
|
||||
# usage ex: python log_cleaner.py file pattern
|
||||
# usage ex: python log_cleaner.py "+/-" file pattern
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
import sys
|
||||
@ -15,15 +15,27 @@ def main():
|
||||
input_file = io.open(sys.argv[1], "r", encoding="utf-8")
|
||||
output_file = io.open("new_" + sys.argv[1], "w", encoding="utf-8")
|
||||
|
||||
pattern = sys.argv[2]
|
||||
inverter = sys.argv[2]
|
||||
if inverter == "-":
|
||||
exclude = True
|
||||
else:
|
||||
exclude = False
|
||||
|
||||
pattern = sys.argv[3]
|
||||
p = re.compile(r".*" + pattern + r".*")
|
||||
|
||||
for line in input_file:
|
||||
val = re.search(p, line)
|
||||
if val:
|
||||
if exclude:
|
||||
pass
|
||||
else:
|
||||
output_file.write(line)
|
||||
else:
|
||||
if exclude:
|
||||
output_file.write(line)
|
||||
else:
|
||||
pass
|
||||
|
||||
output_file.close()
|
||||
input_file.close()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user