如何使sed在“抓取两个关键字之间的文本”时不区分大小写?

3

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的匹配模式?我尝试使用'I',但没有成功。这应该很快就能解决,谢谢!

2个回答

5
如果您的sed支持,您可以使用I ...
sed -n '/Foo/I,/Bar/Ip' text.txt

如果不这样做,你将需要执行类似以下的操作:
sed -n '/[fF][oO][oO]/,/[bB][aA][rR]/p' text.txt

1

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


这是一条与IT相关的命令。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接