C# ASP.NET SQL SERVER

Powershell Grep

For whatever reason I always forget the syntax to quickly find text in a bunch of source files from Powershell. Here it is so I can quickly look it up again:

Get-ChildItem -include *.cs -recurse | Select-String "string to search for"

The Get-ChildItem is the equivalent of dir in DOS.

-include is the param to tell Get-ChildItem which files to include in its search. In this case all CSharp (C#) files.

-recurse means look in subfolders under this one as well. i.e. the one that I'm running the command from.

| - this is the pipe symbol. The results of the search (a collection of files) is piped into the process that will open each file and search for the string.

Select-String - this is the command that will open a file and search for the "string to search for" string in the file. Each found line will be listed.

» Similar Posts

  1. Powershell replace text in files and recurse subdirectories
  2. Powershell Ripped Media Renaming Script
  3. Introduction to Powershell for Developers

» Trackbacks & Pingbacks

    No trackbacks yet.
Trackback link for this post:
http://guyellisrocks.com/trackback.ashx?id=5

» Comments

    There are no comments. Kick things off by filling out the form below.

» Leave a Comment