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?

3

1 Answer 1

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\
/'
2
  • This works, but is ugly.
    – WilliamKF
    Jun 3, 2015 at 23:18
  • @WilliamKF you could also install GNU sed, but that is not a great solution either. If you have a prettier solution, then by all means use it.
    – tekknolagi
    Jun 5, 2015 at 19:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .