powershellgrepxargs

What is the PowerShell equivalent to this grep+xargs command?


I'm trying to create a CLI command to have TFS check out all files that have a particular string in them. I primarily use Cygwin, but the tf command has trouble resolving the path when run within the Cygwin environment.

I figure PowerShell should be able to do the same thing, but I'm not sure what the equivalent commands to grep and xargs are.

So, what would be the equivalent PowerShell version to the following Bash command?

grep -l -r 'SomeSearchString' . | xargs -L1 tf edit

Solution

  • Using some UNIX aliases in PowerShell (like ls):

    ls -r | select-string 'SomeSearchString' | Foreach {tf edit $_.Path}
    

    or in a more canonical Powershell form:

    Get-ChildItem -Recurse | Select-String 'SomeSearchString' | 
        Foreach {tf edit $_.Path}
    

    and using PowerShell aliases:

    gci -r | sls 'SomeSearchString' | %{tf edit $_.Path}