Search code examples
awkignore-case

IGNORECASE in file comparison with awk


Here is my code:

'FNR==NR {a[$1 FS $2 FS $3 FS $4]++; next} !a[$1 FS $2 FS $3 FS $5]' comparegam.txt workstudyusers1.csv >noidea6.txt

it is doing exactly what I need except I need to ignorecase. I have tried using IGNORECASE=1 in various places but I cant get it to work. it either fails, gives me zero results, or ignores it all together. I tried using BEGIN [IGNORECASE = 1} with no luck.

any help would be appreciated, I am at a lost. I am running this in a terminal window, not from a bash script yet. that is the end goal

Note: Output has to contain case to match original files

Here is the exact code that I have tried with IGNORECASE:

awk -F, 'IGNORECASE=1 FNR==NR {a[$1 FS $2 FS $3 FS $4]++; next} !a[$1 FS $2 FS $3 FS $5]' comparegam.txt workstudyusers1.csv >noidea6.txt
awk -F, 'FNR==NR {IGNORECASE=1} {a[$1 FS $2 FS $3 FS $4]++; next} !a[$1 FS $2 FS $3 FS $5]' comparegam.txt workstudyusers1.csv >noidea6.txt
awk -F, '{IGNORECASE = 1} FNR==NR {a[$1 FS $2 FS $3 FS $4]++; next} !a[$1 FS $2 FS $3 FS $5]' comparegam.txt workstudyusers1.csv >noidea6.txt
awk -F, 'BEGIN {IGNORECASE = 1} FNR==NR {a[$1 FS $2 FS $3 FS $4]++; next} !a[$1 FS $2 FS $3 FS $5]' comparegam.txt workstudyusers1.csv >noidea6.txt
awk -F, 'FNR==NR {{IGNORECASE=1} a[$1 FS $2 FS $3 FS $4]++; next} !a[$1 FS $2 FS $3 FS $5]' comparegam.txt workstudyusers1.csv >noidea6.txt

and various iterations of these.


Solution

  • '
      FNR==NR {
        a[tolower($1 FS $2 FS $3 FS $4)]++;
        next
      }
      !a[tolower($1 FS $2 FS $3 FS $5)]
    ' comparegam.txt workstudyusers1.csv >noidea6.txt