awk前后段落关系判断
从如下类型的文件中,找出false段的前一段为i-order的段,同时输出这两段。
2019-09-12 07:16:27 [-][
'data' => [
'http://192.168.100.20:2800/api/payment/i-order',
],
]
2019-09-12 07:16:27 [-][
'data' => [
false,
],
]
2019-09-21 07:16:27 [-][
'data' => [
'http://192.168.100.20:2800/api/payment/i-order',
],
]
2019-09-21 07:16:27 [-][
'data' => [
'http://192.168.100.20:2800/api/payment/i-user',
],
]
2019-09-17 18:34:37 [-][
'data' => [
false,
],
]
BEGIN{
RS="]\n"
ORS=RS
}
{
if(/false/ && prev ~ /i-order/){
print tmp
}
tmp=$0
}
递归正则搜索:
grep -Pz '(?s)\d+((?!2019).)*i-order(?1)+\d+(?1)+false(?1)+'