Keep Line Containing A Certain Word
Keep Lines Containing A Certain Word
Keep Lines Containing A Certain Word keeps only the lines that contain the word or text you type. Paste your text, enter the word and copy the result. It is free and runs in your browser.
Keep Lines Containing a Certain String/Word
Keep Lines Example
He ate his first marshmallow. The sun was very bright. He ran very quickly to the store.
The sun was very bright.
Bookmark: press Ctrl+D (Windows) or Cmd+D (Mac) to save this tool.
What does Keep Lines Containing A Certain Word do?
This tool keeps the lines that contain the word or text you type and removes all other lines. A line stays if the text appears anywhere in it.
The match works on any text, not only whole words, so sun also keeps a line with sunny or sunset. By default capital letters do not matter. Tick Match case to match capitals exactly. Empty lines are removed because they contain nothing.
Use it to pull the lines you need out of a log, a list of names, an export or any long text.
Keep lines containing a certain word examples
Each example shows the word used. Capitals are ignored unless Match case is on.
| Setting | Before | After |
|---|---|---|
| Word: sun | He ate his first marshmallow. The sun was very bright. He ran very quickly to the store. | The sun was very bright. |
| Word: error | ok: saved error: disk full ok: sent error: timeout | error: disk full error: timeout |
| Not a whole word (sun) | sunny day sunset moon | sunny day sunset |
| Match case off (default, cat) | Cat food cat toy dog bowl | Cat food cat toy |
| Match case on (cat) | Cat food cat toy dog bowl | cat toy |
| Empty lines removed (a) | a1 b2 a3 | a1 a3 |
How to keep lines containing a certain word
- 1Add your text
Type or paste your lines into the box, or import a text file. - 2Enter the word
Type the word or text that the lines you want to keep contain. Tick Match case if capitals matter. - 3Click Keep Lines
Only the lines that contain your text stay. Use Undo if you change your mind. - 4Copy it
Click Copy and paste the result where you need it.
When to keep lines containing a word
Good for
Finding the lines you need in a log, a list of names or an export, and removing everything else in one step.
Check first
The text matches inside words too, and spaces count, so cat also keeps a line with category. Lines that do not match are deleted from the box. Use Undo right after if the result is not what you wanted.
Other tools
To delete the matching lines instead, try Remove Lines Containing A Certain Word. To get rid of blank lines, try Remove Empty Lines.
Keep lines containing a certain word FAQ
What does the Keep Lines Containing A Certain Word tool do?
It keeps only the lines that contain the word or text you enter and removes all other lines.
How do I keep lines containing a certain word?
Type or paste your text, enter the word in the Keep lines that contain box and click Keep Lines. The result replaces the text in the box. Click Copy to use it, or Undo to go back.
Does it match whole words only?
No. It matches the text anywhere in a line, so sun also keeps a line with sunny or sunset.
Does it care about capital letters?
Not by default, so Sun, SUN and sun all match. Tick Match case if you want capitals to match exactly.
Can I search for more than one word?
You can search for a phrase, such as red car, and a line is kept if it contains that exact text. It does not search for several different words at once.
What happens to empty lines?
They are removed, because an empty line does not contain your text.
What if no line contains my word?
The tool shows a message and leaves your text as it is, so nothing is deleted by mistake.
Is this tool free and is my text private?
Yes. It is free, needs no account and runs in your browser, so your text is not uploaded to a server.
Looking for more text tools?
Browse Modify ToolsLast updated: 31 October 2026
