darwin / sed / limited regular expressions

darwin / sed / limited regular expressions

  • Written by
    Walter Doekes
  • Published on

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]*//
}'

Back to overview Newer post: python / temporarily blocking signals Older post: callerid in rpid / opensips / kamailio