Remove Specific Lines From a Text

0 line
0 line
Remove lines thatkeywords.

This is a tool that narrows down lines of text by keywords. There are "include", "do not include", "start with", and "end with", and so on. This is useful for log analysis.

  • 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).
  • This tool does not communicate. This site does not collect input values.
日本語 / English

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

Hirota Yano / Programmer
Born in 1988, based in Japan.
© yanohirota.com