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/, / /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/, / /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 ' ‘:

$ 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.

This article was posted by Matty on 2009-05-16 10:48:00 -0400 -0400