![如何分别从同一文件中 grep 两个不同的模式语句](https://linux22.com/image/121425/%E5%A6%82%E4%BD%95%E5%88%86%E5%88%AB%E4%BB%8E%E5%90%8C%E4%B8%80%E6%96%87%E4%BB%B6%E4%B8%AD%20grep%20%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E6%A8%A1%E5%BC%8F%E8%AF%AD%E5%8F%A5.png)
我有一个日志文件,其中有两种不同类型的语句。
一种说法就像
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 ...