case-insensitive search with AWK

Hi All,

How we can perform case-insensitive search with AWK.:rolleyes:

regards,
Sam

there's the builtin for this.
convert BOTH the search and the 'searched in' strings to once case (toupper/tolower) and... search.

how i can do that..?

nawk -v str='FoO' 'tolower(str) ~ tolower($0)' myFile

Thanks for replying i am using awk like:-

awk '/str1/ && /str2/ && /str3/' filename

ok, thanks for sharing.

so how we can make a case-insensitive search for below command

awk '/str1/ && /str2/ && /str3/' filename

just like I outlined above.......

awk 'tolower(str1) ~ tolower($0)' filename

thnx vgersh99

Here is the complete problem.

i want to perform logical AND operation for search. i am passing a space separated string to a variable from web application.

below is my code

KEY="space separated string from web application"
KEY1=`echo $KEY|sed -e 's/ /\/ \&\& \//g'`
awk "/$KEY1/" filename

it is working but not case insensitive.
Any help would be appreciated.

Regards,
Sam

If you are using GNU awk (gawk), set the IGNORECASE builtin variable to 1.

$ gawk 'BEGIN{print "ab" ~ /aB/}'
0
$ gawk 'BEGIN{IGNORECASE=1; print "ab" ~ /aB/}'
1

no, you can not do it like this - there's no 'eval' in awk.

#!/bin/ksh

KEY="space separated string from web application"

nawk -v k="${KEY}" '
  BEGIN {n=split(k,kA)}
    { for(i=1;i<=n;i++) if (tolower($0) !~ tolower(kA)) next;print}' myFile.txt

Thanks vgersh.

Its working..:b::wink: