Question

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
Was it helpful?

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}

OTHER TIPS

I find it easier to grok using a variable, e.g.,

PS> $files = Get-ChildItem -Recurse | 
       Select-String 'SomeSearchString' | 
       %{$_.path}  | 
       Select -Unique
PS> tf edit $files
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top