在配置文件中存在部分配置差异,例如以下格式
#
ecc peer-public-key 127.0.0.1 encoding-type der
public-key-code begin
3400DBAE D5D983F6 D480CC8B 6BD467F8 E15B4C00 AF1D8D66 BD44611B CC514104
55F10318 918323EB 36735C12 5C0A9084 91E35A89 FC7B35BB FB81D2A2 04FC96DE
307AF500 BD8CD70A E5502731 A4FFB90A 78DF9A0B 1DF5D410 7E566C06 EF7C0296
63D3CA5C 3C1D9BE1 E7AAB470 5CC51B8B 8BCF15A4 CD42CB50 52ACE043 ABE6AC2B
D1962D26 69
public-key-code end
peer-public-key end
#
import re
from pathlib import Path
if __name__ == '__main__':
pattern = re.compile(r'^\s*[0-9A-F]{8}.*$')
file1 = Path(r"E:\test\2023-01-01\configuration")
# 遍历file1下所有txt文件
for p in file1.glob("*.txt"):
with open(p, "r", encoding="utf8") as f:
# 遍历文件的每一行
for line in f:
match = pattern.search(line)
if match:
print(p,line)