如何分别从同一文件中 grep 两个不同的模式语句

如何分别从同一文件中 grep 两个不同的模式语句

我有一个日志文件,其中有两种不同类型的语句。

一种说法就像

LOG:Update For User 12932030 statement  @2113 set startduration='2017-01-03 00:01:30'...
LOG:Update For User 12932030 statement @2033 set startduration=endduration ...
LOG:Update For User 12932031 statement @2403 set startduration='2017-01-04 00:02:30'...
LOG:Update For User 12932032 statement  @3113 set startduration='2017-01-09 00:03:30'...
LOG:Update For User 12932033 statement @9313 set startduration=endduration ...
LOG:Update For User 12932034 statement @9126 set startduration=endduration ...

所以我想从这里分别提取两者。但我目前的方法是这样的

grep -i " LOG:Update For User set startduration"  log.csv > result.csv

这两者之间没有区别。我不确定如何在 startduration 之后合并该模式。任何帮助都会受到赞赏。

答案1

尝试使用grep两次:

所需输出类型 1:

 grep -E "LOG:Update For User [0-9]* statement *@[0-9]* set startduration='" log.csv

LOG:Update For User 12932030 statement  @2113 set startduration='2017-01-03 00:01:30'...
LOG:Update For User 12932031 statement @2403 set startduration='2017-01-04 00:02:30'...
LOG:Update For User 12932032 statement  @3113 set startduration='2017-01-09 00:03:30'...

所需输出类型 2:

grep -E "LOG:Update For User [0-9]* statement *@[0-9]* set startduration=[^']" log.csv

LOG:Update For User 12932030 statement @2033 set startduration=endduration ...
LOG:Update For User 12932033 statement @9313 set startduration=endduration ...
LOG:Update For User 12932034 statement  @9126 set startduration=endduration ...

相关内容