我有这个日志文本:
1. SNMPv2-SMI::enterprises.37447.2.1.1.1 type=4 value=STRING: "Test warn level"
2. SNMPv2-SMI::enterprises.37447.2.1.1.2 type=4 value=STRING: "WARN"
3. SNMPv2-SMI::enterprises.37447.2.1.1.3 type=4 value=STRING: "PSBA2STOR051"
4. SNMPv2-SMI::enterprises.37447.2.1.1.4 type=4 value=STRING: "AF-201969"
5. SNMPv2-SMI::enterprises.37447.2.1.1.5 type=4 value=STRING: "PSBA2STOR051"
6. SNMPv2-SMI::enterprises.37447.2.1.1.6 type=4 value=STRING: "117813866"
7. SNMPv2-SMI::enterprises.37447.2.1.1.7 type=4 value=STRING: "test"
8. SNMPv2-SMI::enterprises.37447.2.1.1.8 type=4 value=STRING: "test"
请注意,我的日志中不存在订单号
我只需要提取
Test warn level
test
test
结果需要是:测试警告级别:test-test
我已经尝试过:
(SNMPv2-SMI::enterprises.37447.2.1.1.1.*)\n.*\n.*\n.*\n.*\n.*\n(.*SNMPv2-SMI::enterprises.37447.2.1.1.7.*)\n(.*SNMPv2-SMI::enterprises.37447.2.1.1.8.*)
但它不像我需要的那样工作,它返回孔线
最佳答案
你可以这样做:
sed -e 's/.*37447.2.1.1.[178].*"\(.*\)"/\1/;t;d' test.log
正则表达式搜索包含 37447.2.1.1.1、.7 或 .8 的行:37447.2.1.1.[178]
在这些行中,仅取引号之间的内容:"\(.*\)"
不匹配的行(t
)被抑制(d
):t;d
关于javascript - 解析日志文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56986744/