[英]Sed and regex print only match
sed -er '.*(textsringhere.+?(?= ))(?:.*)((?>\d{4})-(?>\d{2})-(?>\d{2}) (?>\d{2}):(?>\d{2}):(?>\d{2})).* (ERROR.*)' errors.txt
Running the above command on my errors.txt
file simply produces all the matching lines in that file. 在我的
errors.txt
文件上运行以上命令仅会在该文件中生成所有匹配的行。 I had assumed that adding .*
to the beginning of my regex would have forced sed
to replace the entire line with the matches? 我以为在正则表达式的开头添加
.*
会迫使sed
用匹配项替换整行?
Sample 样品
Input: 输入:
Aug 2 16:36:37 App.Dev.thing1 839854b7-749-4f12-89e0-3ad002ab5ffe[[APP/PROC/WEB/0]] 2017-08-02 16:36:37 [main] ERROR o.s.boot.SpringApplication - Application startup failed Aug 2 18:04:46 App.Dev.thing2 eaedf253-df57-4c12-ade6-ea73274dbbc4[[APP/PROC/WEB/0]] 2017-08-02 18:04:46 [main] ERROR o.s.boot.SpringApplication - Application startup failed Aug 3 01:45:55 App.Dev.thing2 eaedf253-df57-4c12-ade6-ea73274dbbc4[[APP/PROC/WEB/0]] 2017-08-03 01:45:55 [http-nio-8080-exec-1] ERROR c.c.v.b.m.c.i.thing2 - Error Processing Batch, this batch will be consumed individually`
Expected output: 预期产量:
App.Dev.thing1 ERROR o.s.boot.SpringApplication - Application startup failed App.Dev.thing2 ERROR o.s.boot.SpringApplication - Application startup failed App.Dev.thing2 ERROR c.c.v.b.m.c.i.thing2 - Error Processing Batch, this batch will be consumed individually`
Simple sed approach: 简单的sed方法:
sed -E 's/.*(App\.\S+).+(ERROR .*)$/\1 \2/' errors.txt
The output: 输出:
App.Dev.thing1 ERROR o.s.boot.SpringApplication - Application startup failed
App.Dev.thing2 ERROR o.s.boot.SpringApplication - Application startup failed
App.Dev.thing2 ERROR c.c.v.b.m.c.i.thing2 - Error Processing Batch, this batch will be consumed individually
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.