Remove Lines Containing

Remove lines containing a word or phrase from any list or document, or flip the switch and keep only the lines that match. Type one or more terms and the filtered text updates as you type, with options for exact case, whole words and regular expressions.

Remove Lines Containing tool

 
   

How to use it

  1. Paste your text, one item per line.
  2. Type the words or phrases to match, one per line, and choose to remove or keep the matching lines.
  3. Turn on Whole word or Regex if you need tighter matching, then copy the result.

How line filtering works

The tool reads your text one line at a time and checks each line against every term you entered. A line counts as a match if it contains at least one of the terms anywhere inside it. Matching lines are then either deleted or kept, depending on the mode, and every other line goes the opposite way.

match   = line contains term1 OR term2 OR ...
remove  → output = lines that do NOT match
keep    → output = lines that DO match

Because a single hit is enough, entering several terms widens the filter. To narrow it instead, use one more specific phrase, or switch on Regex and write the exact pattern you need.

Worked example

Input: Remove lines containing ‘error’ from a log
Result: Only the lines without ‘error’ remain
Input: Keep lines containing ‘@gmail.com’
Result: A list of just the Gmail addresses

Matching options compared

Each row filters the same three lines, Art class, Start date and ART supplies, looking for the term art in remove mode.

OptionsLines matchedLines left
Default (ignore case)All threeNone
Ignore case offStart dateArt class, ART supplies
Whole wordArt class, ART suppliesStart date
Whole word, ignore case offNoneAll three
Regex ^artArt class, ART suppliesStart date

Removing lines by what they contain

Deleting lines by content is one of the most common cleanup jobs, and one of the most tedious to do by hand. A log file needs its debug messages stripped out. A mailing list needs every address from a blocked domain removed. A product export needs the discontinued items gone. In each case the lines you want to drop share a word, and filtering on that word handles hundreds of lines in the time it takes to type it.

Remove or keep

The two modes are mirror images. Remove mode deletes the lines that match and keeps the rest, which suits cleanup. Keep mode does the opposite and returns only the matching lines, which is how you pull a subset out of a larger list: every order from one state, every line mentioning a customer, every URL on one domain.

Getting the match right

Partial matches catch people out. Searching for art also matches start, party and smart, because the letters appear inside those words. Whole word fixes that by matching art only when it stands on its own. Case matters less often, so it is ignored by default, and turning it off lets you separate ART from art when capitals carry meaning.

Regex handles everything the other options cannot. A pattern like ^# matches lines that begin with a hash, ^\s*$ matches blank lines, and \d{3}-\d{4} matches lines holding a phone-number style sequence. If a pattern is invalid the tool says so and leaves your text untouched.

Common uses

  • Stripping debug or info messages out of a log file
  • Removing addresses from a blocked domain in a mailing list
  • Pulling out every line that mentions a customer or product
  • Deleting commented-out lines from code or config
  • Filtering a keyword list down to terms that include a phrase

When to use it

  • You need to delete every line containing a certain word from a long list.
  • You want to keep only the lines of a log file that contain ‘ERROR’ or ‘WARN’.
  • A spreadsheet column of emails has to lose every address from one domain.
  • You are removing lines that start with # from a config file before sharing it.
  • A keyword export needs filtering down to only the phrases that include your brand name.

Related tools

Remove Empty Lines deletes blank lines, including ones that only hold spaces, which is simpler when the lines you want gone have nothing in them.

Remove Duplicate Lines keeps the first copy of each repeated line, the right tool when the problem is repetition rather than content.

Find and Replace changes a word inside lines instead of deleting whole lines, useful when the line is worth keeping but one term is wrong.

Frequently asked questions

Paste your text, type the word in the terms box, and leave the mode on ‘Remove matching lines’. Every line that contains the word disappears as you type, and the count below shows how many were removed.
Yes. Enter each word or phrase on its own line in the terms box. A line is removed if it contains at least one of them, so you can clear several kinds of unwanted lines in one pass.
Switch the mode to ‘Keep only matching lines’. The tool then returns just the lines that include your term and drops everything else, which is how you extract a subset from a longer list.
The term is probably matching inside longer words, so art also catches start and party. Turn on Whole word to match the term only when it stands alone, or turn off Ignore case if capitals matter.
Yes. Tick Regex and each line in the terms box is read as a pattern. For example ^# matches lines starting with a hash and ^\s*$ matches blank lines. An invalid pattern is reported and your text is left unchanged.
Both can do it with a regex find-and-replace, but it takes a pattern and several clicks. Pasting here is quicker for a one-off job, and it previews the result before you copy anything back.
No. Filtering happens entirely in your browser. Nothing you paste is uploaded, and only the main text box is remembered locally so it survives a reload.