I have an input CSV file that looks like this:
123456,ABC,A,,,
123457,DEF,A,H,,
1234568,GHI,,H,,
111111,AAA,A,,,
12345699,XYZ,A,H,,
Now I have an AWK script containing below line with several IF conditions:
BEGIN { FS=","}
{
variable=$1.","$2;
if(variable ~ /^123456.+,ABC/) print "P," $0; else
if(variable ~ /^123457.+,DEF/) print "P," $0; else
if(variable ~ /^123458.+,GHI/) print "R," $0; else
if(variable ~ /^1234599.+,XYZ/) print "P," $0; else print "U" "," $0;}
END { }
After running this AWK script in my input file, I get the following output:
P,123456,ABC,A,,,
P,123457,DEF,A,H,,
R,1234568,GHI,,H,,
U,111111,AAA,A,,,
P,12345699,XYZ,A,H,,
Everything worked so far, but when I had to add additional IF conditions to this AWK script (about 3500), it throws an "exhausted memory" error:
awk: script.awk:1259: if(variable ~ /^123311.+,AB23/) print "P," $0; else
awk: script.awk:1259: ^ memory exhausted
Now the interesting part: firstly, the exhaustion error is always present on line 1259, and secondly, when I delete the number of IF conditions after line 1259 (inclusive 1259), then the script runs smoothly again. Is there any limit to the number of IF conditions inside an AWK / GAWK script?
The AWK version I'm using:
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.3, GNU MP 6.1.0)