nawk issue

Hi,
Below work fine, whenever any character puts, however if we use "(", it's not working.

Working

echo 'Sau(rabh is Nice' | nawk -v a="Saurabh" '{print substr($1,1,match($1, "u"))}'

Not working

echo 'Sau(rabh is Nice' | nawk -v a="Saurabh" '{print substr($1,1,match($1, "\("))}'

Pls advise how to cut the string with "(" pattern.

echo 'Sau(rabh is Nice' | nawk -v a="Saurabh" '{print substr($1,1,match($1, /[(]/))}'

Jean-Pierre.

When a string literal is used as a regular expression, it first has to pass through awk's string parser before the regular expression parser even sees it. By the time the second parser gets it, it's been reduced from \( to ( which is not the correct regular expression.

Use a second backslash so that the string parser sees \\( and outputs \( to the regular expression parser.

However, it's best practice to avoid the complexity of string literal regular expressions when possible.

Regards,
Alister

Removed, Alister explained much better.