我有一個非常大的日志檔案(超過 2GB),如果它們包含“EntityFramework”,我想洗掉所有除錯日志。
info: Microsoft.EntityFrameworkCore.Migrations[20405]
No migrations were applied. The database is already up to date.
dbug: Microsoft.EntityFrameworkCore.Infrastructure[10407]
'IDCDbContext' disposed.
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
info: Hangfire.PostgreSql.PostgreSqlStorage[0]
Start installing Hangfire SQL objects...
在這里我想洗掉下面的日志并保留其他日志
dbug: Microsoft.EntityFrameworkCore.Infrastructure[10407]
'IDCDbContext' disposed.
到目前為止我嘗試過的:
sed -i '/^dbug/{:b,N;/^[[:lower:]]/!bb};/.*EntityFramework.*/d' logs
然而它導致 sed: can't find label for jump to b'
任何的想法?
uj5u.com熱心網友回復:
當前的錯誤是由于b標簽后面的逗號,必須有一個分號。此外,您應該在命令塊中包含/.*EntityFramework.*/d(或更好地,/EntityFramework/d),以便它僅在其中執行:
sed -i '/^dbug/{:b;N;/^[[:lower:]]/!bb;/EntityFramework/d}' logs
請參閱在線演示。
uj5u.com熱心網友回復:
這份作業更適合awk:
awk '!p || !/^[[:blank:]]/ {p = /^dbug:/} !p' file
info: Microsoft.EntityFrameworkCore.Migrations[20405]
No migrations were applied. The database is already up to date.
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
info: Hangfire.PostgreSql.PostgreSqlStorage[0]
Start installing Hangfire SQL objects...
我們保留一個標志p來控制是否列印。p設定為1當一行開始時/dbug:/設定為,并保持設定為dbug:以空格開頭的行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/316068.html
