My Tool Studio
Text

Remove Lines Containing Text

Paste a log, a list or any text and this tool will remove lines containing a word or phrase you choose, or keep only those lines and drop the rest. Add several search terms, one per line, and decide whether a line must match any of them or all of them. A line can match when it contains the text, contains it as a whole word, starts with it, ends with it, is exactly equal to it, or matches a regular expression. Matching ignores capital letters unless you tick Case-sensitive. The lines that were taken out are listed in their own box, so nothing disappears without a trace. Developers use it to filter server logs, and marketers use it to drop brand terms or unwanted keywords from a list. It runs in your browser.

Always freeNo sign upRuns in your browser

How to use

01

Paste your text

Paste into Your text, open a file, or press Try sample to load a short server log with INFO, DEBUG, WARN and ERROR lines.

02

Enter what to look for

Type one search term per line in Search terms. Choose Remove matching lines or Keep only matching lines, then pick how a line matches and whether any or every term must match.

03

Check and copy

Read the lines in, out and removed counter, check the Removed lines box, then press Copy or Download .txt on the result.

Why Remove Lines Containing Text

Example: cleaning a server log

The sample log has eight lines. With the default search terms DEBUG and /healthz and Remove matching lines selected, the two DEBUG lines and the two health check lines are removed, leaving four lines: the server start, the slow query warning, the pricing request and the payment error.

Switch to Keep only matching lines with the single term ERROR and only the payment webhook line remains. Change the logic to Every term matches (AND) with ERROR and payment to find errors about one feature in a long log.

Match types at a glance

Each row shows whether the search term cat matches the line.

Match typethe cat satconcatenatecat foodmy cat
ContainsYesYesYesYes
Contains the whole wordYesNoYesYes
Starts withNoNoYesNo
Ends withNoNoNoYes
Is exactlyNoNoNoNo

Common questions

How do I remove all lines that contain a certain word?
Paste your text, type the word in Search terms and keep Remove matching lines selected. Every line that contains the word disappears from the result, and the Removed lines box shows what was taken out. Matching ignores capitals unless Case-sensitive is ticked.
How do I keep only the lines that contain a word?
Click Keep only matching lines. The result then holds just the lines that match your search terms, in their original order, and everything else goes to the Removed lines box. This is the same as the grep command on Linux and macOS.
Can I filter lines by several words at once?
Yes. Put each word or phrase on its own line in Search terms. With Any term matches (OR), a line matches if it contains at least one of them. With Every term matches (AND), a line matches only when it contains all of them, for example both ERROR and payment.
What is the difference between contains and whole word matching?
Contains matches the text anywhere, so cat matches inside concatenate and category. Contains the whole word only matches when the text is not touching another letter, digit or underscore, so cat matches the cat sat but not category. Whole word works with accented and non-Latin letters too.
Can I remove lines that start or end with certain text?
Yes. Choose Starts with or Ends with in A line matches when it. Starts with # removes comment lines from a config file, and Ends with .jpg filters image paths out of a URL list. Tick Trim spaces on each line if the lines are indented.
How do I use a regular expression to filter lines?
Choose Matches regex and type a JavaScript pattern in Search terms, for example ^\d{4}- for lines that start with a year or (404|500) for status codes. Case-sensitive decides whether the i flag is used. If the pattern is invalid, a message explains why and the text is left as it was.
Can I see which lines were removed by the filter?
Yes. The Removed lines box under the panes lists every line that was taken out, with a Copy button and a .txt download. That makes it easy to check the filter did not catch anything by mistake, or to use the removed lines as a list of their own.
How do I filter lines containing a word in Excel or Notepad++?
In Excel, use a Text Filters, Contains filter on the column, or =FILTER(A:A,ISNUMBER(SEARCH("word",A:A))) in Excel 365. In Notepad++, use Search, Mark with Bookmark line ticked, then Search, Bookmark, Remove Bookmarked Lines. On the command line, grep -v word file.txt removes matching lines.
Is my log file uploaded when I filter lines online?
No. Filtering runs with JavaScript in your browser tab, and a file you open is read on your own device. Logs with IP addresses, emails or internal URLs never leave your computer.

More Text tools

View all