import re
db_name = "my_database" # 需要过滤的数据库名称 traceback_keyword = "Traceback" # 回溯信息的关键字
with open("my_log_file.log", 'r') as f: filtered_logs = [] for line in f: if db_name in line and traceback_keyword in line: filtered_logs.append(line)
print(filtered_logs)
grep "my_database.*Traceback" my_log_file.log
注意,在Linux系统中,正则表达式的特殊字符需要使用转义符号来正确识别。
上一篇:按数据库计算的某个方式分组
下一篇:按数据扩展到新列进行分组