Today I had to face the fact that the
in Darwin 9.4.0 (Mac OS X Leopard 10.5.4) lacks a lot of functionality.
Eg. you cannot embed backslash-escaped characters in the replacement expression of an
The following will output "abcnef" and not "abc" + newline + "ef":
echo 'abcdef' | sed 's/d/\n/'
Backslash-escaped sequences are not recognized in bracket expressions either. So you cannot match a tab character with
or a newline with
This is "normal" behaviour, at least for the Darwin
, but quite unfortunate and makes life a lot more difficult. Eg. there's no way around this regexp (that should match a single line with the newline preceding it) without support for backslash-escapes in brackets:
You can use the
character class as a substitute, but of course it's just a workaround and functionally not equivalent:
However there're problems even with documented functionality. Eg. this
does not support extended regular expressions as described in the
manpage. But the
manpage says that extended regexps are described there.
Eg. the following will output an error instead of "Xc" (the regexp is taken from the
echo 'chchcc' | sed -Ee 's/[[.ch.]]*c/X/'
So multi-character sequences are not accepted as a collating element and you'll get an error message like "RE error: invalid collating element"
Another weirdness: Darwin's
is quite sensitive about separating functions/commands with newlines. You'll find that in many cases you simply must put in a newline here and there or your code won't be accepted. Eg. if you create a function-list, the terminating
must be preceded by a newline, a semi-colon won't do it. Also labels are likely to cause you headaches if you don't put them into their own line. In GNU sed you can create nice (gigantic
) one-liners, because a semi-colon can replace a newline virtually everywhere in the script.
PS: most probably the problems with the Mac OS X
are not specific to Darwin, but came from the FreeBSD roots. Maybe FreeBSD's
worked always like this.
Maybe it's the GNU sed that is "out of the line".
Imho the way GNU sed interprets backslashed escape sequences makes it a lot more "user friendly".