Reputation: 11703
In AWK, is there a way to match pattern containing forward slash /
without actually escaping it?
awk '$1~/pattern/' file
The above command works fine as long as there isn't any /
in the pattern.
I am looking for something similar to what's available in sed for using different separators in search and replace syntax.
Upvotes: 13
Views: 26594
Reputation: 41456
Yes, you can do
awk '$0~v' v="patt/ern"
N.B.: extracted from comments, so upvote them too!
In awk
dynamic regex and regex constant are not exactly same. The example in OP's question was regex constant you turned it into dynamic regex (see. Using Dynamic Regexps).
Upvotes: 14