我正在使用的程序grep用于在系统日志中搜索特定警报,但是我正在寻找的syslog条目的一个元素将专门针对该条目,因此实际上是“随机的”。
我认为我正在寻找的一个例子是:
tail -f log | grep "string {ignore} string"
提前致谢。
我正在使用的程序grep用于在系统日志中搜索特定警报,但是我正在寻找的syslog条目的一个元素将专门针对该条目,因此实际上是“随机的”。
我认为我正在寻找的一个例子是:
tail -f log | grep "string {ignore} string"
提前致谢。
Answers:
您需要在命令中使用WildCards(或Globbing Patterns),grep如下所示:
tail -f log | grep "some_string.*some_string"
其中,.*(注释中@ dsstorefile1也指出)是这里使用的globbing模式。要获取有关Globbing Patterns的更多详细信息,请参阅联机帮助页。
man 7 glob
这将显示:
. (dot) : will match any single character (except end of line) ,
equivalent to ? (question mark) in standard wildcard expressions.
* (asterisk) : the proceeding item is to be matched zero or more times.
ie. n* will match n, nn, nnnn, nnnnnnn
but not na or any other character.
现在,结合这两个你得到:
.* (dot and asterisk) : match any string, equivalent to * in standard wildcards.
另外,正如@Bob在评论中指出的那样,使用效果.*?要好得多.*
.*贪婪,可能捕获超过你想要的。.*?通常更好。
?代替.” 无关。再次阅读我的评论 - 这?是一个修饰符*,使其变得懒惰而不是贪婪的默认值。假设PCRE。
.*更贪婪和使用.*?。
.*你放置{ignore}“任何”通配符的地方。