darwin / sed / limited regular expressions
For someone who is used to using only GNU sed(1)
it may come as a
surprise that some of the metacharacters don’t work with sed on other
OS’es.
Specifically: sed on Darwin (BSD) does not grok \+
, \|
and \?
when in basic regular expression mode (the default).
Switching to extended (modern) regular expression isn’t a good idea if
you’re aiming for compatibility, because the option -E
differs from
the GNU sed option -r
.
Luckily avoiding the metacharacters mentioned shouldn’t generally cause more problems than incurring a bit of typing overhead.
Incompatible:
sed -e '/^) / {
s/ ENGINE=\(MyISAM\|InnoDB\)//
s/ AUTO_INCREMENT=[0-9]\+//
}'
Compatible:
sed -e '/^) / {
s/ ENGINE=MyISAM//
s/ ENGINE=InnoDB//
s/ AUTO_INCREMENT=[0-9][0-9]*//
}'