When matching patterns with /
in them, having to escape the /
quickly becomes unwieldy, ugly:
/\/usr\/share\/man\//
With sed, perl or Vim, I would use a different delimiter for the regex, say :
:
sed '\:/usr/share/man/: do something'
perl -ne 'print if m:/usr/share/man/:'
:g:/usr/share/man/: do something " Vim
How can I avoid this awk? Something like:
awk ':/usr/share/man/: {do something}'
The best I can think of is to use a variable:
awk -v pat='/usr/share/man/' '$0 ~ pat {do something}'
But that is very verbose compared to the sed/perl/vim method.
Of course, there might be other ways to match paths like /usr/share/man/
, but that's not the only place where /
could appear in a pattern.
'$0 ~ "/usr/share/man/" {do something}'
instead of using variable...-v pat='"/'
vs'$0 ~ "\"/"'
).-v regex="^\\\s*$1\\\>"
... I don't think there is a way to use different regex delimiter than/regex/
so will have to use whatever fits case by case basis