Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell: how to grep command output?

Tags:

powershell

In PowerShell I have tried:

alias | select-string Alias 

This fails even though Alias is clearly in the output. I know this is because select-string is operating on some object and not the actual output string.

What can be done about it?

like image 732
Ian Kelling Avatar asked Sep 28 '09 03:09

Ian Kelling


People also ask

How do I select a specific string in PowerShell?

Use Select-String in a function: PS C:\> function search-help { $pshelp = "$pshome\es\about_*. txt", "$pshome\en-US\*dll-help. xml" Select-String -path $pshelp -Pattern $args[0] } This simple function uses the Select-String cmdlet to search the Windows PowerShell Help files for a particular string.


1 Answers

I think this solution is easier and better, use directly the function findstr:

alias | findstr -i Write 

You can also make an alias to use grep word:

new-alias grep findstr 
like image 104
Roi Avatar answered Oct 02 '22 07:10

Roi