AWK negative regular expression

awkregular expression

I am looking to have a awk regular expression that can give all strings not matching a particular word.

using /^((?!word \+).)*/ works in java but does not work in AWK.

Get compilation failed error, escaping the brackets fixes the compilation error, but the regular expression matching is not correct.

It would be great if any one can help with a awk regular expression .

I can not use string" !~ /regex/

I need to use string" ~ /regex/ regex shuould pass for all string but for a specific string.

Strings containing domain should be filtered out.
Input

This is domain test
This is do test
This is test

Output

This is do test
This is test

Need to do with regular expression only. Can not change the Awk code

in AWK its like string" ~ /regex/

so can only pass a regex to achieve this.

Best Answer

While Thomas Dickey's answer is clever, there is a right way to do this:

awk '!/domain/ {print}' <<EOF
This is domain test
This is do test
This is test
EOF

This is do test
This is test
Related Question