$response = Read-Host -Prompt "Set the archive bit on this file?" $files = Select-String -Path "d:\script\*.txt" -Pattern $pattern Here is an example that greps for a string and uses the results in a loop to determine if some action should be taken: $pattern = "tachytelic" If you are on Win-7, then there is powershell, with select-string.
If you don't want to install anything and is on Win XP, try findstr, although it can't do 'orring'. If you need only grep, then there is GnuWin32. I modified GNU grep 2.0 to allow searching of. Well you can have cygwin on Windows so then you have bash, grep, etc.
However, NONE of them allowed me to search through subdirectories (this functionality is easy on unix using the shell's file manipulation tools). There are several ports available that I came across for Windows. Then you can simply pipe to Select-String like this:Ĭat "D:\Script\Lorem-Ipsum.txt" |grep "tachytelic" Loop through results from Select-String GREP is a well known tool in the unix environment. Set-Alias -Name grep -Value Select-String If you want to make it more like Unix/Linux, add an alias to the Select-String cmdlet: There is a command-line tool called FINDSTR that comes with all Windows NT-class operating systems (type FINDSTR / into a Command Prompt window for more. Get-Content "D:\Script\Lorem-Ipsum.txt" |Select-String "tachytelic" Just like grep, you can pipe to Select-String like this: Get-ChildItem -Path "D:\Script\*.txt" -Recurse | Select-String -Pattern 'tachytelic' Piping to Select-String Unlike grep, Select-String does not have the ability to search recursively, but you can pipe output to it from Get-ChildItem, like this: Select-String -Path "D:\script\*.txt" -Pattern 'Tachytelic' Grep Recursively with Get-Childitem Select-String -Path "D:\script\Lorem-Ipsum.txt" -Pattern 'Tachytelic' To grep a simple text file is as easy as: PowerShell brings the functionality of grep with the Select-String cmdlet.
It doesn't copy any files into your Windows folder, but does use the registry to save settings.Unix and Linux have had the incredibly powerful grep tool for decades but windows has always been lacking. By default it will install into your Program Files directory (usually c:\program files\windows grep) but you can install it anywhere.
To install, simply download the file and run. Once you've found what you're looking for, you can open the files found for viewing or editing, or you can replace the text found with something else. The program combines the power and flexibility of traditional command line. Delimited and fixed width data file searching at field-level. Windows Grep is a tool for searching files for text strings that you specify.Saving and retrieval of search criteria I use it all the time as an approximate grep-equivalent on the Windows platform.