views:

275

answers:

1

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
+2  A: 

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 | Select-String 'SomeSearchString' | %{tf edit $_.Path}
Keith Hill
Close, but it's not quite working. As a test I changed the last command to `%{echo HI $_.Fullname}` and I just get "HI" repeated without any names.
Herms
Looks like changing Fullname to Path fixed it.
Herms
Yep, sorry 'bout that. Get-ChildItem outputs FileInfo objects with a FullName property but Select-String outputs a SelectXmlInfo object with a Path property.
Keith Hill