Linux – sed + not work on solaris

linuxsedsolaris

I run the following sed syntax on Solaris machine and on Linux machine

on Linux machine sed do the JOB its remove all characters until the first number.

but why this sed syntax not work on Solaris ?

What I need to change in the sed syntax in order run it on Solaris?

on solaris (sed – not remove the strings until the first number?)

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

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

on linux ( I get good results )

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

  5.3.7.1-12

Best Answer

Solaris generally doesn't have the GNU version of anything by default. This means that the options and arguments you supply will often have to be different to get the same behaviour out of utilities like sed.

Sometimes it will not be possible to get the same behaviour at all, for instance, sed -i won't work on Solaris unless you have installed the GNU version of sed.

From memory, the sed on Solaris supports the "basic" set of regular expressions and this doesn't include the + modifier. You can simulate a + like this:

sed 's/[^0-9][^0-9]*//'

Or you can just use a * for this case:

sed 's/[^0-9]*//'

Solaris usually also has the BSD versions of these utilities installed under /usr/ucb. they are often very similar but occasionally have important differences, such as with ps.