From the info below:
$ cat access.dat
2025/01/01T10:00:01 "GET" /path/resource/api1 User1 500
2025/01/01T10:00:01 "DELETE" /path/resource/api1 User1 503
2025/01/01T04:00:01 "GET" /path/resource/api1 User1 500
2025/01/01T03:00:01 "GET" /path/resource/api1 User1 503
2025/01/01T05:00:01 "PUT" /path/resource/api1 User2 500
2025/01/01T06:00:01 "GET" /path/resource/api1 User1 200
2025/01/01T07:00:01 "GET" /path/resource/api1 User1 201
2025/01/01T08:00:01 "GET" /path/resource/api2 User1 500
2025/01/01T09:00:01 "POST" /path/resource/api2 User2 500
2025/01/01T10:00:01 "POST" /path/resource/api2 User1 400
2025/01/01T11:00:01 "GET" /path/resource/api2 User2 404
I am trying to generate an awk script with if else statement. When doing
cat access.dat | awk '{if ($NF>=400) {print $0}} > failure.dat
the output file is generated successfully. But when adding
cat access.dat | awk '{if ($NF>=400) {print $0} > failure.dat else {print$0} > success.dat}
is marking error. What is wrong in my awk script? How could I generate both failure.dat and success.dat inside if/else statement?
Thank you for your help.
'quotes. Difficult to tell, but you appear to be mixing awk and shell syntax. In awk, (unquoted) failure, success and dat are (undefined) variables, not strings. I suspect awk is throwing syntax on the dot, or possibly evenfatal: cannot redirect to . : Is a directory.