Change regex delimiter in awk patterns

1.8k views Asked by At

Is is possible to change the default regex delimiter (slash) to other characters?

I tried to do it using with sed syntax but it didn't work.

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

The regex I am trying has many slashes. Escaping all of them will make it ugly and unreadable. I tried changing the / to | but it didn't work.

TIA

1

There are 1 answers

4
Dennis Williamson On BEST ANSWER

AWK doesn't support that. Use a variable instead.

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