【问题标题】:How to search for '<' in files using ack in powershell in windows?如何在 Windows 的 powershell 中使用 ack 在文件中搜索“<”?
【发布时间】:2011-07-29 06:55:23
【问题描述】:

我不知道如何转义“

我在 Windows XP 的 powershell 中使用 ack。

ack-grep: chars escaping 的问题与我的非常相似,但针对该问题提供和接受的解决方案对我不起作用。

PS C:\xampp\htdocs> ack abcd
<works as expected>
PS C:\xampp\htdocs> ack <
The redirection operator '<' is not supported yet.
At line:1 char:5
+ ack < <<<<
PS C:\xampp\htdocs> ack \<
The syntax of the command is incorrect.
PS C:\xampp\htdocs> ack '<'
The syntax of the command is incorrect.
PS C:\xampp\htdocs> ack '\<'
The syntax of the command is incorrect.
PS C:\xampp\htdocs> ack [<]
The system cannot find the file specified.
PS C:\xampp\htdocs> ack '[<]'
The system cannot find the file specified.
PS C:\xampp\htdocs> ack '[\<]'
The system cannot find the file specified.
PS C:\xampp\htdocs> ack \Q<\E
The system cannot find the file specified.

【问题讨论】:

    标签: windows powershell escaping ack


    【解决方案1】:

    您有什么理由不想使用 PowerShell 的正则表达式搜索?

    Select-String '<' *.*
    
    ## or
    dir -r | Select-String '<'
    

    【讨论】:

    • 我不知道该功能存在。谢谢你通知我。您建议的第二个命令解决了我的问题。
    • 这个工具和 Unix 工具(ack, ag, ripgrep, grep)之间的性能比较有没有好的资源?
    【解决方案2】:

    PowerShell 中的转义字符是反引号:

    PS C:\xampp\htdocs> ack `<
    

    【讨论】:

    • 问题不是PowerShell,问题出在ack或者shell端。
    • 当我输入“ack `
    【解决方案3】:

    你的意思是awk?如果是这样,那么你所要做的就是:$awk '/&lt;/ filename'

    由于我没有安装 ack,我无法 100% 验证,但我会尝试这段代码:

    ack  '<' --output '$1' -h
    

    如果这不起作用,那么我建议通读 man ackack --help 页面。

    【讨论】:

    • 我已编辑问题以在尝试 'ack
    • @Tom 我已经更新了我的答案。希望你会发现它很有用。
    • 感谢您帮助 Moses,但是当我键入“ack '
    猜你喜欢
    • 2012-12-04
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-19
    相关资源
    最近更新 更多