2

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
Eytan
  • 611
  • 6
  • 13
  • 27
  • 1
    Take a look at sunfreeware.com, you can download the GNU version of utilities from there as packages. – user9517 Jan 10 '12 at 16:58
  • possible duplicate of [How do I use sed or awk to remove text?](http://serverfault.com/questions/348426/how-do-i-use-sed-or-awk-to-remove-text) – MadHatter Jan 10 '12 at 17:04

1 Answers1

6

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.

Ladadadada
  • 26,337
  • 7
  • 59
  • 90