1
我有這樣的記錄:用grep一個字符串遵循的一系列數字
2014-09-24 10:07:44 +0000 severity=INFO, Completed 200 OK in 955ms (Views: 566.4ms | ActiveRecord: 246.9ms)
2014-09-24 10:06:53 +0000 severity=INFO, Completed 404 Not Found in 13ms (Views: 12.0ms | ActiveRecord: 0.0ms)
2014-09-24 10:06:43 +0000 severity=INFO, Completed 500 OK in 939ms (Views: 547.8ms | ActiveRecord: 253.0ms)
2014-09-24 10:05:44 +0000 severity=INFO, Completed 501 OK in 721ms (Views: 495.1ms | ActiveRecord: 198.2ms)
2014-09-24 10:04:43 +0000 severity=INFO, Completed 200 OK in 997ms (Views: 592.6ms | ActiveRecord: 238.4ms)
2014-09-24 10:03:43 +0000 severity=INFO, Completed 401 OK in 983ms (Views: 584.8ms | ActiveRecord: 237.0ms)
我想,以獲得含有不同類型的錯誤,所有行做的grep用正則表達式。 因此,例如:
所有客戶端的錯誤:已完成4 *
2014-09-24 10:06:53 +0000 severity=INFO, Completed 404 Not Found in 13ms (Views: 12.0ms | ActiveRecord: 0.0ms)
2014-09-24 10:03:43 +0000 severity=INFO, Completed 401 OK in 983ms (Views: 584.8ms | ActiveRecord: 237.0ms)
所有服務器錯誤:已完成5 *
2014-09-24 10:06:43 +0000 severity=INFO, Completed 500 OK in 939ms (Views: 547.8ms | ActiveRecord: 253.0ms)
2014-09-24 10:05:44 +0000 severity=INFO, Completed 501 OK in 721ms (Views: 495.1ms | ActiveRecord: 198.2ms)
你有什麼建議嗎?
你能解釋一下什麼樣的兩個命令嗎? – user3702916 2014-09-24 11:03:01
這兩個命令都會在日誌文件中搜索給定的模式。第一種模式是:''Completed [0-9]''表示文本'Completed'後跟任意數字。第二種模式是「完成」,後跟數字「4或5」。 – anubhava 2014-09-24 11:05:31