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?

WilliamKF
  • 8,058

1 Answers1

0

You can make a literal newline in your script, like so:

cat version | sed -e 's/[0-9][0-9][0-9][0-9][0-9:M]*-[abp]/Ver\
/'
tekknolagi
  • 1,420