1
I'm using the following sed
command:
cat version | sed -e 's/[0-9][0-9][0-9][0-9][0-9:M]*-[abp]/Ver\n/'
Which normalizes like this:
4330M-p -> Ver<newline>
This works fine with GNU SED, but with BSD SED on Mac OS X, the \n turns into an n
like this:
4330M-p -> Vern
To normalize some output that contains a version number that changes over time to a static string, followed by a newline. This is used as part of testing where the output after sed
processing is compared via diff
with a known golden file and we don't want failures due to the version number changing and further need a newline added for our purposes.
How can I replace with a string that adds a newline in a way that works on both GNU and BSD version of sed
, or should I just install GNU sed
on Mac OS X because this cannot be done?
I haven't tried BSD sed, but perhaps something like
\d13
or something like\x0a
? that works in GNU does it work in BSD? – barlop – 2015-06-03T23:11:38.337@barlop, Nope, the backslash is eaten by BSD
sed
and you getVerd13
andverx0a
. – WilliamKF – 2015-06-03T23:17:49.440this may be of interest http://stackoverflow.com/questions/1421478/how-do-i-use-a-new-line-replacement-in-a-bsd-sed and http://unix.stackexchange.com/questions/42321/how-can-i-instruct-bsd-sed-to-interpret-escape-sequences-like-n-and-t and http://superuser.com/questions/307165/newlines-in-sed-on-mac-os-x
– barlop – 2015-06-03T23:26:15.180