awk: warning: escape sequence '\<' treated as plain '>'

Posted on in Categories last updated September 29, 2012

I‘m trying to match words using GNU awk command and getting the following error:

echo 'foo bar this that blah' | awk '{gsub("\<regex-word\>", "NEW-WORD");print}'

But getting the following warning on screen and it is not working:
awk: warning: escape sequence `\<' treated as plain `<' awk: warning: escape sequence `\>' treated as plain `>'

How do I fix this problem under Unix like operating systems?


You need escape the backslashes too:

{gsub("\\<regex-word\\>", "NEW-WORD");

In this example:

echo 'foo bar this that blah' | awk '{gsub("\\<regex-word\\>", "NEW-WORD");print}'

Leave a Comment