所以我有這個日誌文件正則表達式匹配一個而不是另一個
2017-06-14 08:53:41,472 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Chrome 57.0
2017-06-14 08:53:41,472 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Chrome 57.0
2017-06-14 08:53:41,472 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Chrome 57.0
2017-06-14 08:53:45,010 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Chrome 57.0
2017-05-23 18:38:35,966 - [info] access - example.com "GET HTTP/1.1" 52228 200 0 159 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-05-23 18:38:37,811 - [info] access - example.com "GET HTTP/1.1" 53716 200 0 301 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-06-14 08:53:45,010 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Chrome 57.0
2017-06-14 08:53:45,011 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Chrome 57.0
2017-06-14 08:53:45,011 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Chrome 57.0
2017-06-14 09:40:04,506 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Chrome 58.0
2017-06-14 12:32:40,779 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Chrome 57.0
2017-06-14 13:22:40,988 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:24:45,023 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:25:16,091 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:26:18,138 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-05-23 18:38:34,874 - [info] access - example.com "GET HTTP/1.1" 673 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-05-23 18:38:35,428 - [info] access - example.com "GET HTTP/1.1" 662 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-05-23 18:38:57,901 - [info] access - example.com "GET HTTP/1.1" 745 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-06-14 13:27:20,425 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:28:22,237 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:28:53,225 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:29:24,139 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:32:30,227 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-05-23 18:38:33,881 - [info] access - example.com "GET HTTP/1.1" 603 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-05-23 18:38:34,111 - [info] access - example.com "GET HTTP/1.1" 675 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-05-23 18:38:34,144 - [info] access - example.com "GET HTTP/1.1" 481 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-06-14 13:33:01,250 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:35:05,346 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:36:07,563 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:39:13,557 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:39:33,777 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Chrome 58.0
2017-05-23 18:38:58,445 - [info] access - example.com "GET HTTP/1.1" 859 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-05-23 18:38:58,485 - [info] access - example.com "GET HTTP/1.1" 819 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-05-23 18:38:58,720 - [info] access - example.com "GET HTTP/1.1" 654 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-05-23 18:38:58,760 - [info] access - example.com "GET HTTP/1.1" 624 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-06-14 13:39:44,517 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:45:25,661 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:46:58,629 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:49:02,639 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:49:40,884 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-05-23 18:38:34,369 - [info] access - example.com "GET HTTP/1.1" 683 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-05-23 18:38:58,181 - [info] access - example.com "GET HTTP/1.1" 886 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-05-23 18:38:58,210 - [info] access - example.com "GET HTTP/1.1" 662 304 0 0 "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
2017-06-14 13:50:04,713 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:50:27,767 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:50:27,767 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 13:50:27,767 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: Internet Explorer 11.0
2017-06-14 14:04:44,239 - [error] javascript - "Javascript error: undefined - url: undefined - line: undefined - browser: PhantomJS 2.1
我想找到所有與正則表達式的一個文件中包含的「Internet Explorer 11」的錯誤行的錯誤,但不是。
使用regex101.com我能搞清楚這個正則表達式我能找到任何匹配這個正則表達式:(\[.*error.*\])(?!.*Internet Explorer 11.*)
現在我想知道我怎麼可以在命令執行此線來測試這一點。
我試過
這些節目沒有輸出(不得不逃離!
grep "(\[.*error.*\]){1,}(?\!.*Internet Explorer 11.*)" /var/log/upstart/app.log
egrep "(\[.*error.*\]){1,}(?\!.*Internet Explorer 11.*)" /var/log/upstart/app.log
任何人都知道如何做到這一點?任何幫助表示讚賞
另外,轉義'!'有點難,''foo''會嘗試歷史擴展,''\ foo 「'打印反斜槓和感嘆號。解決方案是使用單引號,或完全禁用歷史擴展。 – ilkkachu
爲什麼你需要一個正則表達式?有沒有理由你不能'grep -F'[錯誤]'|例如,grep -v -F'Internet Explorer 11'' –