Change regex delimiter in awk patterns

Is it possible to change the default regex separator (slash) to other characters?

I tried to do this using sed syntax , but that didn't work.

$ gawk '\|bash| { print } ' backup.sh
gawk: |bash| { print }
gawk: ^ syntax error

The regular expression I'm trying has a lot of slashes. Escaping over them will make him ugly and unreadable. I tried changing / to | but it didn’t work.

TIA

+5
source share
1 answer

AWK does not support this. Use a variable instead.

gawk 'BEGIN {pattern = "/"} $0 ~ pattern {print}' backup.sh
+1
source

All Articles