How to Remove Lines Containing a Word (Excel, Notepad++, VS Code and Online)

· 5 minutes read

How to Remove Lines Containing a Word (Excel, Notepad++, VS Code and Online)

Log files full of DEBUG noise, CSV exports with test records, keyword lists with brand terms you want to exclude – sooner or later everyone needs to remove all lines containing a certain word. Doing it by hand is slow and you will miss some. Here is how to do it in seconds, with whatever tool you have at hand.

The fastest way: remove lines containing a word online

  1. Open remove lines containing.
  2. Paste your text into the input box (or open the file).
  3. Type the word or phrase into Words or phrases. Need several? Put each on its own line – a line is removed if it contains any of them.
  4. Choose what to do with matching lines: Remove them, or Keep only them to do the opposite.
  5. Fine-tune with the options:
    • Case sensitive – Error will no longer match ERROR.
    • Whole words only – cat matches "the cat sat" but not "category". Works with accented words too.
    • Regular expressions – for patterns like ^# (lines starting with #) or 5\d\d$ (HTTP 5xx status at the end of a line).
  6. Copy or download the result. The counters show how many lines were removed and kept.

Your text is processed in the browser, so it works offline and nothing is uploaded.

How to remove rows containing a word in Excel

  1. Click any cell in your data and choose Data → Filter.
  2. Open the filter drop-down of the column, pick Text Filters → Contains…, type the word and confirm.
  3. Select the visible rows (row numbers on the left), right-click and choose Delete Row.
  4. Turn the filter off with Data → Filter again. Only rows without the word remain.

To keep only the matching rows instead, use Does Not Contain… in step 2.

In Excel 365 you can also produce a filtered copy with one formula, leaving the original untouched:

=FILTER(A2:A1000, ISERROR(SEARCH("word", A2:A1000)))

SEARCH ignores letter case; use FIND for a case-sensitive match.

How to remove lines containing a word in Google Sheets

=FILTER(A2:A, A2:A<>"", NOT(REGEXMATCH(A2:A, "(?i)word")))

(?i) makes the match case-insensitive. For several words, separate them with a pipe: "(?i)debug|healthcheck". Remove NOT(…) to keep only the matching lines.

How to remove lines containing a word in Notepad++

Option 1 – bookmarks (no regex needed):

  1. Press Ctrl+M (Search → Mark).
  2. Enter the word, tick Bookmark line and click Mark All.
  3. Go to Search → Bookmark → Remove Bookmarked Lines.

Use Remove Unmarked Lines instead to keep only the lines with the word.

Option 2 – regular expression replace:

Open Ctrl+H, choose Search Mode: Regular expression, and replace

^.*word.*(\R|$)

with nothing. \R matches any line break, so the whole line disappears instead of leaving an empty one.

How to do it in VS Code

Open Find and Replace (Ctrl+H), enable regular expressions (the .* button), search for

^.*word.*\n?

and click Replace All with an empty replacement. For a case-sensitive match, enable the Aa button.

How to remove lines containing a word on the command line

grep -v prints lines that do not match:

grep -v 'DEBUG' app.log > app-clean.log

Useful variations:

grep -vi 'debug' app.log           # ignore case
grep -vw 'cat' list.txt            # whole words only
grep -vF -f stopwords.txt list.txt # remove lines containing any term from a file
grep 'ERROR' app.log               # keep only matching lines

With sed you can edit a file in place (on macOS use sed -i ''):

sed -i '/DEBUG/d' app.log

In PowerShell:

Get-Content app.log | Select-String -Pattern 'DEBUG' -NotMatch | ForEach-Object Line | Set-Content app-clean.log

Select-String is case-insensitive by default; add -CaseSensitive if needed.

Common pitfalls

  • Partial matches. Removing lines with cat also removes "category" and "concatenate". Use whole-word matching.
  • Case. Logs often mix Error, ERROR and error. Decide whether they should all match.
  • Special characters. In regex mode ., (, ? and + have special meanings. If you are searching for plain text like file(1).txt, turn regex mode off (or escape the characters).
  • Empty lines left behind. Some editors delete the text but not the line break. Clean up with the empty lines remover.
  • Accidental overwrite. sed -i changes the file immediately. Keep a copy, or write the result to a new file first.

FAQ

Can I remove lines containing several different words at once?

Yes. In the online tool put each word on its own line. With grep, use grep -v -e word1 -e word2 or a file of terms with -f.

How do I keep only the lines that contain a word?

Select Keep only them in the tool – it works like grep 'word'. In Excel use the Contains text filter and copy the visible rows.

How do I remove duplicate lines after filtering?

Send the result to the duplicate remover with the "Send result to…" button.

Is there a limit on file size?

The online tool handles files of several megabytes comfortably; the limit is your browser's memory. For multi-gigabyte logs, grep -v is the better choice.