【问题标题】:ACK-GREP ignore whitespacesACK-GREP 忽略空格
【发布时间】:2014-03-10 13:53:42
【问题描述】:

我最近切换到 ACK-GREP(再见,再见标准 grep),我唯一缺少的是在搜索时忽略空格的选项。

例子:

@param(
    'lol', int, "Foo bar",
    can=False, hasBurger=True
)

我想通过

找到它

ack @param('lol'

我必须在 .ackrc 中更改/添加什么来强制这种行为?

【问题讨论】:

    标签: regex grep ack


    【解决方案1】:

    你不能。不是因为空间,而是因为新线。来自手册页的常见问题解答:

    *Can I do multi-line regexes?*
       No, ack does not support regexes that match multiple lines.  Doing so would require 
       reading in the entire file at a time.
    

    但是,您可以构建自己的管道并删除所有空格:

     cat YOURFILE | tr -d [:space:] | ack --type=TYPE -o PATTERN
    

    但我想,这并不是你想要的。

    【讨论】:

    • 您能否提出其他解决方案?
    • 现在它确实找到了一些东西,但我丢失了有关行号的信息。顺便说一句,我可以通过这种方式递归地对所有文件和子文件夹进行分类吗?
    • 关于递归:你可以使用xargs:find . -print0 | xargs -0 cat ...。不过,也许你应该看看pcregrep
    猜你喜欢
    • 2015-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    相关资源
    最近更新 更多