sed + does not work on solaris

1

I try to use a sed line with a + on a Solaris machine and on a Linux machine.

on Solaris sed does not remove the strings until the first number like I want:

   solaris:/ ROOT > echo "Release............5.3.7.1-12"  | sed 's/[^0-9]\+//'

   Release............5.3.7.1-12

on Linux I get the expected results:

  linux tmp]# echo "Linux Release............5.3.7.1-12"  | sed 's/[^0-9]\+//'

  5.3.7.1-12
  • Why is this sed syntax not working on Solaris?

  • What do I need to change in the syntax in order for it to run on Solaris?

Eytan

Posted 2012-01-10T15:55:51.890

Reputation: 47

Answers

0

Normally, escaping the + character (\+) results in a literal +, not a modifier. This is not the case with sed on Ubuntu 10.04, but it might not be on Solaris.

My best guess it that this is implementation-specific, so sed 's/[^0-9]\+//' might work.

You could also try sed -r 's/[^0-9]\+//' (where -r means extended regular expressions). It works on Ubuntu 10.04.

Dennis

Posted 2012-01-10T15:55:51.890

Reputation: 42 934

1

that doesn't seem to be correct - it's just that the solaris sed doesn't support '+'. the same question by the same author here seems to have more info : http://serverfault.com/questions/348490/sed-not-work-on-solaris

– Richlv – 2016-04-11T11:25:09.063