November 15th, 2014

PowerTip: Using PowerShell to Search Text Files for Letter Pattern

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to search the contents of all text files in a folder for a specific letter pattern.

Hey, Scripting Guy! Question How can I use Windows PowerShell to search the contents of a lot of files in a folder for
           the occurrence of a specific letter pattern?

Hey, Scripting Guy! Answer Use the Select-String cmdlet, and specify the pattern and the path to the files.
           Windows PowerShell automatically reads the contents of the text files, and it will show the path
           and the line number of the file that contains the pattern. Here is an example that searches
           all text files in the c:\fso folder for the pattern gps:

Select-String -Pattern "gps" -Path c:\fso\*.txt

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.