Issue
I have a very large log file (more than 2GB) and would like to remove all debug logs if they contain '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...
Here I would like to remove the log below and keep the others
dbug: Microsoft.EntityFrameworkCore.Infrastructure[10407]
'IDCDbContext' disposed.
What I've tried so far:
sed -i '/^dbug/{:b,N;/^[[:lower:]]/!bb};/.*EntityFramework.*/d' logs
However it results in sed: can't find label for jump to b'
Any idea?
Solution
The current error is due to the comma after the b
label, there must be a semi-colon. Also, you should include /.*EntityFramework.*/d
(or better, /EntityFramework/d
) into the command block so that it is executed only inside it:
sed -i '/^dbug/{:b;N;/^[[:lower:]]/!bb;/EntityFramework/d}' logs
See the online demo.
Answered By - Wiktor Stribiżew Answer Checked By - David Goodson (WPSolving Volunteer)