2010-01-20 114 views
8

我正嘗試創建一個CLI命令,讓TFS檢出所有其中包含特定字符串的文件。我主要使用Cygwin,但tf命令在Cygwin環境中運行時無法解析路徑。與此Bash命令等效的PowerShell是什麼?

我認爲PowerShell應該可以做同樣的事情,但我不確定對grepxargs的等效命令是什麼。

那麼,等效的PowerShell版本到以下Bash命令是什麼?

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

回答

12

使用PowerShell中某些UNIX別名(如ls):

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

或者在更典型Powershell的形式:

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

並使用PowerShell的別名:

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

我發現它更容易溝通使用變量,例如,

PS> $files = Get-ChildItem -Recurse | 
     Select-String 'SomeSearchString' | 
     %{$_.path} | 
     Select -Unique 
PS> tf edit $files 
相關問題