I need to search for a keyword using awk, but I want to perform a case-insensitive (non case sensitive) search.
I think the best approach is to capitalize both the search term ("key word") and the target line that awk is reading at the same time. From this question I how to use toupper
to print in all uppercase, but I don't know how to use it in a match because that answer just shows printing and doesn't leave the uppercase text in a variable.
Here is an example, given this input:
blablabla
&&&Key Word&&&
I want all
these text and numbers 123
and chars !"£$%&
as output
&&&KEY WORD&&&
blablabla
I'd like this output:
I want all
these text and numbers 123
and chars !"£$%&
as output
This is what I have, but I don't know how to add in toupper
:
awk "BEGIN {p=0}; /&&&key word&&&/ { p = ! p ; next } ; p { print }" text.txt