How to use circumflex in the field delimiter in AWK?

Viewed 207

I want to use ,^ as the field delimiter, as follows:

echo "hello,^my,^friend" | awk -F',^' '{print $2}'

The above command should return my. But actually it returns nothing, why? I cannot figure it out.

1 Answers

In extended regular expressions, circumflex character's special meaning is preserved irrespective of its position in the entire expression unless it's quoted or inside a bracket expression, so you need to quote it.

$ echo "hello,^my,^friend" | awk -F',\\^' '{print $2}'
my

Compare BRE Expression Anchoring to ERE Expression Anchoring.

Related