Remove Specific Lines From a Text

  • You can enter multiple keywords separated by line breaks.
  • If multiple keywords are specified, they will be used in the OR condition (matching any of them).
日本語 / English

Input text: 0 line

Result: 0 line

Remove lines thatkeywords.

I often use it for log analysis.

How to use

For example, if there is such a log.

INFO  2019-01-31 15:00:00.000 1234/process1 message
ERROR 2019-01-31 15:00:00.000 1234/process1 message
INFO  2019-01-31 15:00:00.000 4321/process2 message
INFO  2019-01-31 15:00:00.000 1234/process1 message
INFO  2019-01-31 15:00:00.000 4321/process2 message
INFO  2019-01-31 15:00:00.000 4321/process3 message
INFO  2019-01-31 15:00:00.000 1234/process1 message

Example 1

Select “do not contain” and input “process1” as the keyword.
-> Remove lines not containing process1.

INFO  2019-01-31 15:00:00.000 1234/process1 message
ERROR 2019-01-31 15:00:00.000 1234/process1 message
INFO  2019-01-31 15:00:00.000 1234/process1 message
INFO  2019-01-31 15:00:00.000 1234/process1 message

Example 2

Select “contain” and input “process1” as the keyword.
-> Remove lines containing process1.

INFO  2019-01-31 15:00:00.000 4321/process2 message
INFO  2019-01-31 15:00:00.000 4321/process2 message
INFO  2019-01-31 15:00:00.000 4321/process3 message

Example 3

Select “do not start with” and input “ERROR” as the keyword.
-> Remove all lines except a line starting with ERROR

ERROR 2019-01-31 15:00:00.000 1234/process1 message

Caution

This tool simply narrows down by keywords. Therefore, depending on the contents of the log, the line you want to see may be removed.

For example, if you input “process1” in ” do not containing” in the following log, even the stack trace rows will be removed.

INFO  2019-01-31 15:00:00.000 1234/process1 message
ERROR 2019-01-31 15:00:00.000 1234/process1 message
    com.process1.Exception
        at com.foo(foo:2)
        at com.bar(bar:3)
        at com.baz(baz:5)
INFO  2019-01-31 15:00:00.000 4321/process2 message
INFO  2019-01-31 15:00:00.000 1234/process1 message
INFO  2019-01-31 15:00:00.000 4321/process2 message
INFO  2019-01-31 15:00:00.000 4321/process3 message
INFO  2019-01-31 15:00:00.000 1234/process1 message
INFO  2019-01-31 15:00:00.000 1234/process1 message
ERROR 2019-01-31 15:00:00.000 1234/process1 message
    com.process1.Exception
INFO  2019-01-31 15:00:00.000 1234/process1 message
INFO  2019-01-31 15:00:00.000 1234/process1 message

Please use it after understanding the movement.

By the way, line deletion is realized by regex. For example, “do not containing” looks like this.

/^(?!.*(keyword1|keyword2)).*$(\r\n|\r|\n)?/gm

Regex are introduced in the following articles.
Regex: Delete lines that match the conditions