What is the PowerShell equivalent to this Bash command?

Herms picture Herms · Jan 20, 2010 · Viewed 9.1k times · Source

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

Answer

Keith Hill picture Keith Hill · Jan 20, 2010

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}