Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell: filter string list

Tags:

powershell

This seems like a very basic thing to do, but I am new to PowerShell and can't figure this out or find an example online...

I am trying to filter a list of strings. This list of strings is the result of a "svn list" command (Subversion list of repository files), like:

svn list -R PATHTOREPOSITORY

I have tried

svn list -R PATHTOREPOSITORY | where {$_ -like "stringtomatch"}

and this does not work. How can I fix it?

like image 649
Mike Gates Avatar asked Feb 19 '10 16:02

Mike Gates


2 Answers

You might consider using -match instead of -like. -Match is more powerful (regex based) and will work like you were initially expecting:

svn list -R PATHTOREPOSITORY | where {$_ -match 'stringtomatch'} 
like image 186
Keith Hill Avatar answered Sep 19 '22 14:09

Keith Hill


Use:

svn list -R PATHTOREPOSITORY | where {$_ -like "*stringtomatch*"}
like image 45
Mike Gates Avatar answered Sep 18 '22 14:09

Mike Gates