How to make this sed capture text between two case insensitive keywords?

test.txt

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

hello

world

Bar
Yes!
Foo

How are ya?!

Bar

Have a great day!

sed-grab text

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

Output

Hello there, welcome! Foo

hello

world

Bar
Foo

How are ya?!

Bar

How to make this register insensitive? For example, say "FOO" or "bAr" will match the matching pattern for sed? I tried "I", no luck. That should be quick, thanks guys!

+3
source share
2 answers

If your sed supports it, you can use I ...

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

If not, you will need to do something like

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

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

+1
source

All Articles