34 lines
779 B
Python
34 lines
779 B
Python
#-------------------------------------------------------------------------------
|
|
# log_cleaner
|
|
# 22/03/2022
|
|
# tool script used to remove unwanted lines from log files
|
|
#
|
|
# usage ex: python log_cleaner.py file pattern
|
|
#-------------------------------------------------------------------------------
|
|
|
|
import sys
|
|
import re
|
|
import io
|
|
|
|
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]
|
|
p = re.compile(r".*" + pattern + r".*")
|
|
|
|
for line in input_file:
|
|
val = re.search(p, line)
|
|
if val:
|
|
pass
|
|
else:
|
|
output_file.write(line)
|
|
|
|
output_file.close()
|
|
input_file.close()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|