输入:
This script may take a while to run, especially on a busy podmaster.
Generating Syslog TopN list on node for last 3 hours.
Top 5 hosts for Day: Oct8 between 02:00:00 and 02:59:59
Rank Number of Alerts Host
---- ---------------- ----
1 3124 aaa.ab.com
2 2294 bbb
3 2157 ccc
4 832 ddd
5 816 eee
Top 5 hosts for Day: Oct8 between 01:00:00 and 01:59:59
Rank Number of Alerts Host
---- ---------------- ----
1 5495 fff
2 2625 ggg
3 998 hhh
4 752 iii
5 741 jjj
Top 5 hosts for Day: Oct8 between 00:00:00 and 00:59:59
Rank Number of Alerts Host
---- ---------------- ----
1 2747 kkk
2 876 lll
3 780 mmm
4 724 nnn
5 309 ooo
我使用下面的正则表达式来匹配这种格式。
\s+1+\s+([\d]+)\s+([\w]+)[\S\s]*?\s+1+\s+([\d]+)\s+([\w]+)[\S\s]*?\s+1+\s+([\d]+)\s+([\w]+)
上面表达式的输出是
$2 = aaa.ab.com
$4 = fff
$5 = kkk
但是我需要正则表达式来分别匹配排名1。
Example output:
$2 = aaa.ab.com
$4 = fff
$5 = kkk
我们必须写一个正则表达式来匹配ab.com和ab.com不存在的情况。 请帮我解决一下。
答案 0 :(得分:0)
\s+1+\s+([\d]+)\s+((?:\w+)(?:[\.]ab[\.]com)?)[\S\s]*?\s+1+\s+([\d]+)\s+((?:\w+)(?:[\.]ab[\.]com)?)[\S\s]*?\s+1+\s+([\d]+)\s+((?:\w+)(?:[\.]ab[\.]com)?)