Remove Lines Containing
Delete lines that contain a specific word or pattern
What Is the Remove Lines Containing Tool?
The Remove Lines Containing tool deletes every line in your text that includes a word or pattern you specify, leaving only the lines that do not match. You type your target word or phrase into the filter field, click Remove Matching Lines, and the tool goes through the whole block and drops anything that contains it. It is useful for filtering out unwanted entries from lists, stripping header or footer lines from exported data, or removing any category of line you can identify by a consistent keyword.
It is a fairly targeted tool, but when the situation calls for it, doing this manually across a long list is the kind of work nobody particularly wants to sit through.
How to Use This Tool
- Paste or type your text into the input box above.
- Type the word or pattern you want to target into the filter field. Any line that contains this text anywhere within it will be removed from the output.
- Click Remove Matching Lines and the tool deletes all lines containing your specified text, returning only the lines that did not match.
- Copy the result using the Copy button, or select and copy manually. Use Clear to reset the input.
When Would You Use This?
Stripping comment lines from a block of exported data or code output, where every comment line starts with a consistent character like # or // and you just want the data rows without the annotations.
Removing header, footer, or label rows from a copied table or report that got included when you pasted the content and now need to be filtered out before the data goes anywhere useful.
Filtering a list of URLs, file paths, email addresses, or entries to exclude any line that contains a specific word, domain, or pattern you want out of the final set.
Examples
Removing lines containing a specific word
Input : apple
banana error
kiwi
mango error
grapePattern: error
Output : apple
kiwi
grape
Stripping comment lines from data
Input : # This is a comment
alice@email.com
# Another comment
bob@email.com
carol@email.comPattern: #
Output : alice@email.com
bob@email.com
carol@email.com
Removing header rows from exported data
Input : Name,Email,Country
Alice,alice@email.com,UK
Bob,bob@email.com,US
Name,Email,Country
Carol,carol@email.com,CAPattern: Name,Email,Country
Output : Alice,alice@email.com,UK
Bob,bob@email.com,US
Carol,carol@email.com,CA
Filtering URLs by domain
Input : https://example.com/page1
https://spam-site.com/bad
https://example.com/page2
https://spam-site.com/also-badPattern: spam-site.com
Output : https://example.com/page1
https://example.com/page2
Frequently Asked Questions
How do I delete lines containing a specific word?
Paste your text into the input box, type the word into the filter field, and click Remove Matching Lines. Every line that contains that word, anywhere within it, is removed from the output.
Is the matching case sensitive?
It depends on the tool's current settings. If case sensitivity is off, "Error" and "error" and "ERROR" all match the same pattern. Check the output to confirm the behavior for your specific input.
Can I use this to remove lines that start with a specific character?
You can type that character into the filter field and it will match any line containing it, though that also includes lines where the character appears in the middle or end. If you need to match only lines that start with a specific character, a more specific pattern or regex-capable tool would be more precise.
How do I remove comment lines from code?
Type # or // or whatever comment character your code uses into the filter field and click Remove Matching Lines. Every line containing that character is dropped. If the comment character also appears in non-comment lines, check the output for any lines that got removed unexpectedly.
How do I filter lines in a text file?
Paste the file contents into the input box, enter the word or pattern you want to exclude, and run the tool. Copy the result and save it back to your file.
Can I remove multiple different patterns at once?
Typically one pattern per run. For multiple patterns, run the tool once for each, using the output from the previous run as the input for the next.
What if I want to keep only lines containing a word instead of removing them?
That is a different operation, sometimes called "grep" or "keep lines containing." This tool removes matching lines. For the opposite behavior, you would need a different tool.
How do I remove lines containing a word in Python?
Use a list comprehension: [line for line in text.splitlines() if 'word' not in line]. For case-insensitive matching, use 'word' not in line.lower(). For a no-code option, use this tool.
Does it match partial words or only whole words?
It matches any line where the pattern appears anywhere, including as part of a longer word. So filtering for "error" would also remove a line containing "errors" or "errorlog".