awk case-insensitive

can I tell awk to be case insensitive for one operation without setting the ignorecase value ?

thanks,
Steffen

You cannot use IGNORECASE to make certain rules case-insensitive and other rules case-sensitive, because there is no way to set IGNORECASE just for the pattern of a particular rule.
To do this, you must use character sets or tolower.
However, one thing you can do only with IGNORECASE is turn
case-sensitivity on or off dynamically for all the rules at once.

I know I cannot use IGNORECASE for only certain commands, only globally.

I didnt want to IGNORECASE anyway. My problem is that I have to look for a match in a file using awk and the search string is a variable. Since I cannot control if the variable is lower or upper case, I need to have awk search for any lower or uppercase match(es).

Steffen

if you are searching for word "goat" use this
/[Gg][Oo][Aa][Tt]/

I know that, but I have a user input variable as the search string, I cannot alter the variable to [Aa][Bb][Cc].....

Steffen

Why not use the functions tolower()/toupper() functions in awk. That might help you.

I don't know this function, will take a look at it

thanks,
Steffen

try this

awk -v var="abc"  '
function regexp(var)
{
x=tolower(var)
y=toupper(var)
len=length(var)
str=""
for( i = 1; i <= len ; ++i)
        str=str"[" substr(x,i,1) substr(y,i,1) "]"
return str
}
{ if (match($0,regexp(var )))
    print $0
}' file