1

I am able to use Select-String to return a list of files that contain some text that i am looking for:

Get-ChildItem *.cs -recurse | Select-String -SimpleMatch ".ToList()" | group path | select name

What I am trying to do is apply subsequent filters to the result of my query. I would like to do something like:

if($fileSet -eq $null)
{
    $fileSet = Get-ChildItem *.cs -recurse | Select-String -SimpleMatch ".ToList()" | group path | select name 
}

$fileSet | Select-String -SimpleMatch "Additional Term" | group path | select name

I think i need a way to pipe the contents of an array of files ($fileSet) to Select-String; however I'm pretty sure I going about this all wrong. Any help appreciated!

2 Answers 2

2

How about something like:

Get-ChildItem *.cs -Recurse | Select-String -SimpleMatch ".ToList()" | ForEach-Object {
  $_ | Select-String -SimpleMatch "Additional Term"
} | Group-Object Path | Select-Object -ExpandProperty Name
Sign up to request clarification or add additional context in comments.

Comments

0

Was able to massage the accepted answer to also maintain something similar to structure in the question

if($fileSet -eq $null)
{
    $fileSet = Get-ChildItem *.cs -recurse | Select-String -SimpleMatch ".ToList()"
}

$fileSet | foreach {
   Select-String -Path $_.Path -SimpleMatch "Additional Term"
} | Group-Object Path | Select-Object -ExpandProperty Name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.