簡體   English   中英

使用 Sed 和 grep 作為日志文件

[英]using Sed with grep for the log file

每當我執行 error_log($ex->getTraceAsString()) 時,我都試圖使 php 錯誤日志明顯好,但它打印了 \n 所以我想出了可能性,結果證明我應該從終端本身做到這一點

所以我做

 tail -f /var/log/apache2/error.log | sed 's/\\n/\n/g'

但以前我曾經為我的日志做過

tail -f /var/log/apache2/error.log | grep production

對於包含關鍵字 production 的日志

但我想要他們兩個我應該怎么做?所以我的兩個標准都有效

我試過

tail -f /var/log/apache2/error.log | grep production | sed 's/\\n/\n/g'
tail -f /var/log/apache2/error.log | sed 's/\\n/\n/g' | grep production 
(tail -f /var/log/apache2/error.log | grep production) | sed 's/\\n/\n/g'
(tail -f /var/log/apache2/error.log | sed 's/\\n/\n/g') | grep production 

但這些都不起作用。 我應該怎么辦?

使用 /..../ 等將搜索字符串添加到 sed 語句:

tail -f /var/log/apache2/error.log | sed -n '/production/s/\\n/\n/gp'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM