测试.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 的匹配模式?我试过“我”,没有运气。这应该很快,谢谢大家!
最佳答案
如果您的 sed 支持它,您可以使用 I ...
sed -n '/Foo/I,/Bar/Ip' text.txt
否则你将不得不做类似的事情
sed -n '/[fF][oO][oO]/,/[bB][aA][rR]/p' text.txt
关于regex - 如何使这个 sed 'grab text between 2 keywords' 不区分大小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10558605/