【问题标题】:How to make this sed 'grab text between 2 keywords' case-insensitive?如何使这个 sed“在 2 个关键字之间抓取文本”不区分大小写?
【发布时间】:2012-05-11 21:03:33
【问题描述】:

test.txt

Welcome notice
------------------------
Hello there, welcome! Foo

hello

world

Bar
Yes!
Foo

How are ya?!

Bar

Have a great day!

sed - 抓取文本

$ sed -n '/Foo/,/Bar/p' test.txt

输出

Hello there, welcome! Foo

hello

world

Bar
Foo

How are ya?!

Bar

如何使这个不区分大小写?例如,说 'FOO' 或 'bAr' 将匹配 sed 的匹配模式?我试过用“我”,没有运气。这应该很快,谢谢大家!

【问题讨论】:

    标签: regex bash sed match


    【解决方案1】:

    如果你的 sed 支持它,你可以使用 I ...

    sed -n '/Foo/I,/Bar/Ip' text.txt
    

    如果没有,你将不得不做类似的事情

    sed -n '/[fF][oO][oO]/,/[bB][aA][rR]/p' text.txt
    

    【讨论】:

      【解决方案2】:

      sed -n '/Foo/,/Bar/Ip' test.txt

      【讨论】:

        猜你喜欢
        • 2020-06-29
        • 1970-01-01
        • 1970-01-01
        • 2012-09-06
        • 1970-01-01
        • 2017-06-16
        • 2011-02-01
        • 2021-01-01
        相关资源
        最近更新 更多