>_ IzzyLab

Hands-on task

This task is step 2 of the course “Logs: analysis and housekeeping”

Delete lines by pattern

easy~3 min

The log /root/app.log has lines of level DEBUG — they get in the way. Delete all lines containing DEBUG and write the cleaned log to /root/clean.log (the remaining lines — unchanged and in the same order).

What you'll practise:
  • sed
  • address pattern
  • deleting lines
  • log filtering

Topic breakdown

sed can apply a command not to all lines, but only to those that match an address pattern written between slashes. The delete command drops the matched lines from the stream, while all others pass straight through in their original order — a convenient way to filter a log by a keyword. The result, as usual, is directed to a separate file.

What's checked

  1. DEBUG lines deleted, the rest intact
  2. the other lines are not lost

What it looks like