8

我正在尝试创建一个CLI命令来让TFS检查所有包含特定字符串的文件。我主要使用Cygwin,但该tf命令在 Cygwin 环境中运行时无法解析路径。

我认为 PowerShell 应该能够做同样的事情,但我不确定grepxargs的等效命令是什么。

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

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

2 回答 2

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}
于 2010-01-20T16:21:33.977 回答
2

我发现使用变量更容易理解,例如,

PS> $files = Get-ChildItem -Recurse | 
       Select-String 'SomeSearchString' | 
       %{$_.path}  | 
       Select -Unique
PS> tf edit $files
于 2012-07-16T11:39:35.587 回答