Site icon Kommands.com

Searching for a String or Value in a File using Command Prompt and PowerShell

In many situations, it’s necessary to search for a specific string or value in a file. Windows provides two built-in tools, Command Prompt and PowerShell, to easily search for a string or value in a file. In this article, we will go over the steps and commands to use both Command Prompt and PowerShell to search for a string or value in a file.

Command Prompt Method:

  1. Open the Command Prompt by pressing the Windows key + R, typing “cmd” and pressing Enter.
  2. To search for a specific word or string in a file, use the following command:
findstr /I WORD FILE PATH


For example, to search for the word “book23” in the file “c:\testing\Testdoc.txt”, you would use the following command:

findstr /I book23 c:\testing\Testdoc.txt

The “/I” switch is used to ignore case sensitivity. If you don’t use the “/I” switch, the search will be case-sensitive.

You can also search for a string or value in a file without specifying a specific word or string,

findstr book c:\testing23\Testdoc.txt

If the word or string you are searching for contains the same characters as other words or strings in the file, you can modify the word or string slightly to ensure it returns the correct result.

For example, if you are searching for the word “Content2” in a file and it is not returning any results, you can try searching for “Content” instead.

findstr Content c:\testing23\Testdoc.txt


PowerShell Method:

Open PowerShell by pressing the Windows key + X and selecting PowerShell.

To search for a specific word or string in a file, use the following command:

Select-String -Path "FILE PATH" -Pattern "WORD"


For example, to search for the word “book23” in the file “c:\testing\Testdoc.txt”, you would use the following command:

Select-String -Path "c:\testing\Testdoc.txt" -Pattern "book23"


You can also search for a string or value in a file without specifying a specific word or string,

Select-String -Path "c:\testing23\Testdoc.txt" -Pattern "book"


PowerShell also has the option to ignore case sensitivity.

Select-String -Path "c:\testing23\Testdoc.txt" -Pattern "book" -CaseSensitive:$false


Using either the command prompt or PowerShell, you can easily search for a specific string or value in a file. Both methods involve using a specific command that searches for the specified string or value in the specified file. It’s also possible to ignore case sensitivity in both methods by using the appropriate switch or parameter. It’s important to note that searching for a string or value in a large file may take some time, and it’s recommended to be as specific as possible when searching for a string or value to reduce the search time. Additionally, it’s also helpful to check for any common variations of the string or value you are searching for, to ensure that the correct result is returned.

Exit mobile version