Getting sed to substitute a newline on Linux and Solaris hosts

While crafting an install script a week or two ago, I came across an annoying issue with the Solaris sed utility. When I tried to substitute the string ‘, ‘ with a newline, I got this:

$ grep foo gemlist | sed -e ‘s/foo.*(//’ -e ‘s/)//’ -e ‘s/, /\n/g’
2.4n2.3n2.2n2.1

But when I ran the same sustitution with GNU sed, everything worked as expected:

$ grep foo gemlist | gsed -e ‘s/foo.*(//’ -e ‘s/)//’ -e ‘s/, /\n/g’
2.4
2.3
2.2
2.1

It turns out that the Solaris sed is extremely dated, and requires an explicit newline instead of a ‘\n’:

$ grep foo gemlist | gsed -e ‘s/foo.*(//’ -e ‘s/)//’ -e ‘s/, /\
$>/g’
2.4
2.3
2.2
2.1

In the end I found it easier to write my installer in Python, which made life much much easier.

3 Comments

Ex-Solaris User  on May 16th, 2009

Solaris vi is also dated.

Jeff Schroeder  on May 18th, 2009

Solaris userland is ancient… news at 11!

You’re also using a useless use of cat.

grep foo gemlist | gsed -e ’s/foo.*(//’ -e ’s/)//’ -e ’s/, /\

matty  on May 18th, 2009

Hey Jeff,

Good point on wasting a fork() and exec() with cat. I went ahead and updated the post to reflect your comment.

Thanks!
- Ryan

Leave a Comment