---
title: "Findstr Command : Empower you to Search Text in Files Easily"
description: "Looking for a way to find texts without having to manually scrolling through a list? This tutorial will get you started in finding texts and files with the findstr command."
canonical: "https://adamtheautomator.com/findstr/"
---

# Findstr Command : Empower you to Search Text in Files Easily

> Looking for a way to find texts without having to manually scrolling through a list? This tutorial will get you started in finding texts and files with the findstr command.

Source: https://adamtheautomator.com/findstr/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Findstr Command : Empower you to Search Text in Files Easily](https://adamtheautomator.com/wp-content/uploads/2021/09/Getting-Started-with-the-Findstr-Command.jpg)

# Findstr Command : Empower you to Search Text in Files Easily

[![](https://secure.gravatar.com/avatar/1117c2efdf8de21446d7ab331de2a85cb0b9b13ce18b09d9f7bc369451f2ce77?s=192&d=mm&r=g)Ekekenta Odionyenfe .C](https://adamtheautomator.com/author/ekekenta-odionyenfe/)22 September 20216 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Command Line](/tag/command-line/)[Command Prompt](/tag/command-prompt/)[Windows 10](/tag/windows-10/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Finding Words in Files](#finding-words-in-files)
*   [Printing the Line Numbers of Strings](#printing-the-line-numbers-of-strings)
*   [Finding Strings that End in Specific Characters](#finding-strings-that-end-in-specific-characters)
*   [Finding and Modifying Text in a File](#finding-and-modifying-text-in-a-file)
*   [Finding Files that Contain a Specific Word](#finding-files-that-contain-a-specific-word)
*   [Finding All Files in a Directory that Contain a Specific Word](#finding-all-files-in-a-directory-that-contain-a-specific-word)
*   [Changing Output Background Color](#changing-output-background-color)
*   [Comparing Two Files’ Contents to Return their Common Strings](#comparing-two-files-contents-to-return-their-common-strings)
*   [Conclusion](#conclusion)

Manually searching through some text can be a nightmare, but lucky for you, you have the `findstr` at your fingertips. `findstr` is a command that will find a string in a file on Windows when given a specific pattern.

In this tutorial, you’ll learn to find and extract information from text files and general text snippets.

Let’s get on with it!

## Prerequisites

This tutorial uses Windows 10 Build 19042, but older versions like Windows 7 and 8.1 will also work.

## Finding Words in Files

Let’s start learning about the `findstr` command by finding words in files. The `findstr` command is a built-in command-line tool, which sends specific lines of matching words to the standard output device. Adding parameters to the `findstr` command gives you flexibility in finding words in files and even finding files.

Get yourself familiar with the `findstr` command syntax below.

```bash
findstr <parameter> <string> <file_path>
```

Now to demonstrate how to find a line of text in a text file:

1\. Create a folder named _C:\\findstr_, then create a text file named _test.txt_ with your preferred text editor in the _C:\\findstr_ folder.

2\. Copy and paste the random content below in the _test.txt_ file and save it. The snippet below is from a SQL query, but `findstr` doesn’t care; the text can be anything.

```powershell
CREATE TABLE IF NOT EXISTS `customer` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `beneficary` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `loan` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

'created' datetime DEFAULT NULL,

CREATE DATABASE test
```

3\. Finally, change the working directory (`cd`) to the _C:\\findstr_ folder, and run the `findstr` command below to search for the word `CREATE` in the `test.txt` file. The `findstr` command prints each line of text with the word `CREATE` in it.

> _Since the `findstr` command is case-sensitive, it will only look for the exact word you specified and matches its text case._

```bash
cd c:\findstr
findstr CREATE text.txt
```

> _When you need to find multiple words instead, specify additional words before the file to search the word from, like this: `findstr /C:CREATE SELECT customer test.txt`. This command lets you find the terms `CREATE`, `SELECT,` and `customer` in the `test.txt file`._

Below, you can see the command displays all lines of texts where there’s a word “CREATE” in them.

![Finding a word in a file](https://adamtheautomator.com/wp-content/uploads/2021/09/image-175.png)

Finding a word in a file

> _Perhaps you want to ignore text cases in finding words in files. If so, append the `/i` parameter to the `findstr` command, like this: `findstr /i CREATE text.txt`. The `/i` parameter tells the `findstr` command to find lines of texts with the word CREATE in them regardless of the text case._

## Printing the Line Numbers of Strings

Instead of finding strings only, you can also find the line numbers of strings, perhaps to confirm the location of a specific function in a script file. You can find the line numbers of strings by adding the `/n` parameter in the `findstr` command.

Run the `findstr` command below to find the word `CREATE` in the test.txt file, and print the line numbers (`/n`) of each string where there’s a word `CREATE`.

```bash
findstr /n CREATE test.txt
```

Notice below the matched string printed out to the console prefaced with their line numbers.

![Printing the line numbers of strings](https://adamtheautomator.com/wp-content/uploads/2021/09/image-176.png)

Printing the line numbers of strings

## Finding Strings that End in Specific Characters

Rather than just searching a fully typed string, you may also want to find the words that end with specific characters. In that case, adding the `/r` parameter and a [regular expression](https://windows.tips.net/T001364_Introduction_to_Regular_Expressions.html) to the `findstr` command is what you’ll need. A regular expression is a string that consists of special characters designed to match a pattern.

Run the command below with the `/r` parameter to process the search string as a regular expression (`[a-z]*te`). As a result, the command finds all the words in the _test2.txt_ file that ends with (`te`).

```bash
 findstr /r [a-z]*te test2.txt
```

Below, you can see the command printed a string with the word **CREATE**, ending in **te.**

![Finding string that ends with a character](https://adamtheautomator.com/wp-content/uploads/2021/09/image-177.png)

Finding string that ends with a character

> _To specify the first characters of the word to find instead, reverse the expression from `[a-z]` to `[z-a]`, like this: `findstr /r [z-a]*cr test2.txt`. The command finds words that start with `cr` from the `test2.txt` file._

## Finding and Modifying Text in a File

Other than finding strings, you can also modify a string found in a file. Perhaps you regularly change a file’s content, such as removing the blank lines. If so, add the `/v` with the `findstr` command to automatically remove all blank lines in a file.

Run the `findstr` command below to read the _test.txt_ file, from beginning to end of the text (`^$`), and write (`>`) them to a file called `test3.txt`.

The `/v` parameter tells the `findstr` command not to include blank lines when writing the text to the _test3.txt_ file.

```bash
findstr /v "^$" test.txt > test3.txt
```

Now, open the _test3.txt_ file, and you’ll see the same texts from _the test.txt_ file, but with no blank lines.

![Viewing Modified Texts in the test3.txt File](https://adamtheautomator.com/wp-content/uploads/2021/09/image-178.png)

Viewing Modified Texts in the test3.txt File

## Finding Files that Contain a Specific Word

The `findstr` command doesn’t only let you find words in files. You can also find files that contain a specific word! Perhaps, you forgot the name of a text file you created, but you remember a particular word you wrote in it. In that case, the `findstr` command can surely help.

To demonstrate finding files containing a specific word, create a text file called _test2.txt,_ and put in the text below to that text file.

```powershell
CREATE DATABASE test
```

Now run the `findstr` command to find all text files (`*.txt`) that contain the word `CREATE` in them. The `/m` parameter tells the `findstr` command to print the file name only if a file includes matched string. At the same time, the `/c` parameter enforces the literal match of the searched string.

```bash
findstr /m /c:"CREATE" *.txt
```

Below, you can see the files that contain a string (`CREATE DATABASE test`) printed out to the console.

![Finding files that contain a specific word](https://adamtheautomator.com/wp-content/uploads/2021/09/image-179.png)

Finding files that contain a specific word

## Finding All Files in a Directory that Contain a Specific Word

You’ve just learned how to find a file with a specific word. But what if you forgot the extension of the file you’re looking for? The `findstr` command also lets you search all the files in a directory and subdirectories via a specified word.

1\. Create three more text files named _test4.txt_, _test5.txt,_ and _test6.txt_ in the _findstr_ directory.

2\. Next, add the text below to each of the text files.

```powershell
fastify.adHook ('onRequest', async(request, reply) => {
```

3\. Finally, run the command below to find all files (`*.*`) in the current and all subdirectories that contain the word `fastify` while ignoring the text case of the search string. `findstr /s /i fastify *.*` Below, you can see the files found that contain the word “fastify” along with their respective locations.

```bash
findstr /s /i fastify *.*
```

Below, you can see the files found that contain the word “fastify” along with their respective locations.

![Finding all text in a directory ](https://adamtheautomator.com/wp-content/uploads/2021/09/image-180.png)

Finding all text in a directory

## Changing Output Background Color

Perhaps you also want the file locations of the matched string printed in a nice-looking color. If so, let the `/a` parameter do the magic. The `/a` parameter displays directories and filenames with a highlighted background.

Run the command below to find all files (`*.*`) in the current and subdirectories (`/s`) that contain the word `fastify` while ignoring the text case (`/i`) of the search string.

Notice the `/a` parameter added to highlight the files found with a specified color (`2F`). Two hex digits specify the color attribute. The first digit (`2`) is the background color, and the second (`F`) is the foreground.

```bash
findstr /a:2F /s /i fastify *.*
```

You can see below that each file that contains the word “fastify” has a green background color.

> _Run the `color /?` command to know more about the color attributes._

![Highlighting Files Found that Contain the Word "Fastify"](https://adamtheautomator.com/wp-content/uploads/2021/09/image-181.png)

Highlighting Files Found that Contain the Word “Fastify”

## Comparing Two Files’ Contents to Return their Common Strings

Instead of searching for a string in a file, try comparing the contents of two files and print out their commonalities. Perhaps to confirm if both files contain the same function or configuration. In that case, you’ll need to append the `/g` parameter. The `/g` parameter gets the content of a file and compares it to another file’s content.

Run the `findstr` command with the `/g` parameter to compare the `test4.txt` and `test5.txt`, then print their common matched strings.

```bash
findstr /g:"test.txt" "test2.txt"
```

Below, you can see the command printed the common string in the _test4.txt_ and _test5.txt_ files.

![Joining two files command output](https://adamtheautomator.com/wp-content/uploads/2021/09/image-182.png)

Joining two files command output

## Conclusion

Throughout this tutorial, you’ve learned the basic understanding of finding texts in files with the `findstr` command. You’ve also known to find texts in a file and rewrite them on a different file simultaneously.

Now, how would you leverage the `findstr` command in your daily routine? Perhaps you plan to create shell [scripts](https://adamtheautomator.com/powershell-script-examples/) that automate finding and rewriting texts?

Related:[5 PowerShell Script Examples To Inspire You to Get Scripting](https://adamtheautomator.com/powershell-script-examples/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Ffindstr%2F&text=Findstr%20Command%20%3A%20Empower%20you%20to%20Search%20Text%20in%20Files%20Easily)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Ffindstr%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Ffindstr%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26989-monitor-windows-servers-prometheus-grafana-codex.webp)

### [How to Monitor Windows Servers with Prometheus and Grafana](/monitor-windows-servers-prometheus-grafana/)

Set up Windows Server monitoring with windows\_exporter, Prometheus, Grafana, and Alertmanager. Learn how to secure port 9182, scrape targets, and validate alerts.

![](https://adamtheautomator.com/wp-content/uploads/2026/05/featured_image-11.webp)

### [How to Troubleshoot Active Directory Replication Errors](/troubleshoot-active-directory-replication-errors/)

Troubleshoot Active Directory replication errors by isolating 1311, 1722, 2087, and USN rollback issues with repadmin, dcdiag, DNS, RPC, and KCC checks.

![](https://adamtheautomator.com/wp-content/uploads/2026/04/featured_image-6.webp)

### [How to Survive the 2026 Secure Boot Certificate Expiry](/survive-2026-secure-boot-certificate-expiry-3/)

Deploy Windows UEFI CA 2023 before the June 2026 certificate expiry. Inventory devices, update OEM firmware, and trigger enrollment via Intune or PowerShell registry settings.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
