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?

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
  • 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 Jun 27 '17 at 22:50
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.