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
- Paste your text, one item per line.
- Type the words or phrases to match, one per line, and choose to remove or keep the matching lines.
- 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
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.
| Options | Lines matched | Lines left |
|---|---|---|
| Default (ignore case) | All three | None |
| Ignore case off | Start date | Art class, ART supplies |
| Whole word | Art class, ART supplies | Start date |
| Whole word, ignore case off | None | All three |
Regex ^art | Art class, ART supplies | Start 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.