Suppress awk warnings

1

On a script, I get some warning of the form awk: warning: escape sequence \( treated as plain (. Since I want to use the output of that script to do stuff, I want it to output only results and not warnings.

I can correct that warning easily, but is there a way to get rid of all warnings in awk?

Pedro Montoto García

Posted 2013-12-20T16:40:58.273

Reputation: 145

Answers

2

Warnings and error messages are generally sent to stderr, and that seems to be the case for awk, so redirecting stderr to /dev/null should keep you from seeing those messages, like this:

awk your_options your_file 2>/dev/null

garyjohn

Posted 2013-12-20T16:40:58.273

Reputation: 29 085

This seems like a bad idea, because you will miss any actual errors you should be aware of. Is there any way to suppress that warning, or all warnings ONLY, and still see any significant errors? Looking for something more elegant/clean than simply piping stderr to 'grep -v' ;-) – BobDoolittle – 2017-06-27T22:50:03.043

0

The problem with directing stderr to /dev/null (as suggested by the answer from @garyjohn) is that you miss ALL errors, not just this warning you'd like to suppress. So you'll miss anything more significant going wrong. Bad idea, in general. NEVER do this unless there is no other alternative. Luckily in this case there is a much better alternative.

The clean solution to the OP's issue is to use "\\(" instead of "\(". That's what awk/gawk is trying to warn you about - it's not just whining for fun.

BobDoolittle

Posted 2013-12-20T16:40:58.273

Reputation: 124