regex - 如何使这个 sed 'grab text between 2 keywords' 不区分大小写?

标签 regex bash sed match

测试.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/

相关文章:

python - Python 中的不完全 JSON 字符串反序列化

regex - 为什么这个正则表达式测试不起作用?

sed + 需要删除文件中以### 开头的每一行

linux - 不重复的排列列

regex - sed 中的后置代码过滤器

php - 重写 URL 的 Glype (nginx)

regex - 提取字符串中括号之间的数字

linux - 用于查找最新文件匹配模式的 Bash 函数

bash - 在这个简单的Docker包装脚本示例中,如何正确传递当前包含空格的工作目录路径?

sed 命令中的 Bash 变量