My Tool Studio
Text Tools·4 min read

Remove Lines Containing a Word: Filter Text Fast

A 4,000 line log file arrives and you only care about the twelve lines that mention the payment service. Or a keyword export needs every row with your brand name stripped out before it goes to the ads team. Both are the same job: look at each line, decide whether it matches, and keep or drop it. Doing it by hand is slow and error prone, while a line filter does it in one pass and shows you exactly what it took out. This guide covers how to remove lines containing a word, how the match types differ, how to combine several terms, and the traps that make a filter catch too much or too little.

Remove or keep: two sides of the same filter

Decide which half you want.

Every line filter splits a text into two piles: lines that match and lines that do not. Remove Lines Containing Text lets you choose which pile becomes the result. Remove matching lines deletes the lines that contain your terms, which is what you want for noise such as debug messages, health checks or unwanted keywords. Keep only matching lines does the opposite and returns just the lines that contain the terms, the same idea as the grep command on Linux and macOS.

The other pile is never thrown away silently. It appears in the Removed lines box under the result, with its own copy and download buttons. That box is worth a glance every time, because it is the fastest way to notice that a filter caught a line you meant to keep.

How the match types differ

Contains is not the only question.

The menu called A line matches when it decides what counts as a hit. Contains is the loosest: the term can sit anywhere in the line, inside other words too. That is right for log levels such as ERROR, but wrong for short words, because cat also matches concatenate and category.

Contains the whole word fixes that by requiring that the term does not touch another letter, digit or underscore. Starts with and Ends with look only at the edges, which suits comment lines that begin with a hash or file paths that end in .log. Is exactly compares the whole line, handy for removing a placeholder row such as N/A. Matches regex hands you full control with a regular expression.

  • Contains: ERROR, timeout, /healthz.
  • Contains the whole word: short words like cat, id or test.
  • Starts with: # for comments, 2026-09 for one month of a dated log.
  • Ends with: .jpg, .pdf or a closing tag.
  • Is exactly: blank placeholders such as N/A or a repeated header row.

Worked example: cleaning a server log

Eight lines in, four out.

The sample log in the tool has eight lines from a small web server: a start-up message, two DEBUG lines, a slow query warning, a request for /pricing, a payment error and two requests for /healthz. With the search terms DEBUG and /healthz, each on its own line, and Remove matching lines selected, four lines disappear. What is left is the start-up message, the warning, the pricing request and the error, which is the part a person actually needs to read.

Now switch to Keep only matching lines and replace the terms with the single word ERROR. The result is one line, the payment webhook timeout. Change the logic to Every term matches (AND) and use ERROR and payment together, and you have a filter for one feature's errors that still works when the log grows to thousands of lines.

Combining several search terms

OR widens, AND narrows.

Put each term on its own line in Search terms. With Any term matches (OR), a line is a hit when it contains at least one of them, so the filter gets wider as you add terms. That is the setting for a blocklist, such as removing every line that mentions any of five competitor brands.

With Every term matches (AND), a line is a hit only when it contains all of the terms, so each extra term makes the filter narrower. That is the setting for questions like which lines mention both a customer ID and the word refund. Case is ignored in both modes unless you tick Case-sensitive, which matters for log levels that also appear in lowercase inside messages.

Filtering with regular expressions

When a word is not enough.

Some filters are patterns rather than words. Lines that start with a date, lines that contain a 4xx or 5xx status code, lines with an email address. Choose Matches regex and type a JavaScript regular expression per line. ^\d{4}- matches lines that begin with a year, and \s(4\d\d|5\d\d)\s picks out common HTTP error codes in an access log.

If a pattern has a mistake, such as an unclosed bracket, the tool shows the error message and leaves your text as it was instead of guessing. Test a new pattern with Keep only matching lines first, since the result then shows exactly what the pattern matches.

Mistakes that make a filter catch too much

Check the removed pile.

Most bad results come from one of these:

  • Short terms with Contains: id matches inside video, valid and hidden. Use Contains the whole word.
  • Forgetting that matching ignores case: the term Error also matches error messages written in lowercase. Tick Case-sensitive when the difference matters.
  • Indented lines with Starts with: a line that begins with spaces does not start with #. Tick Trim spaces on each line.
  • A blank line in Search terms is ignored, but a term with a trailing space is not, so a term like foo with a space after it only matches foo followed by a space.
  • Using OR when you meant AND, which turns a narrow question into a very wide filter.

Line filtering next to the other list tools

One step in a cleanup.

Filtering is often one step of several. Remove Duplicate Lines is the next stop when a log repeats the same message, and Sort Lines Alphabetically groups what is left. When two lists need comparing rather than one list filtering, Compare Two Lists shows what is only in each. And when the job is changing text inside lines rather than dropping whole lines, Find and Replace Text is the right tool.

Try it now

Open Remove Lines Containing Text

The tool is one click away. No sign up, no upload, no payment.

Open Remove Lines Containing Text