Mar 022012
 

Out of the box, inserting newlines does not work with sed on OS X:

% echo foo,bar,baz | sed -e 's/,/\n/g'            
foonbarnbaz

The simple solution is to use GNU sed, which is already installed (as gsed), instead of the default BSD version:

% echo foo,bar,baz | gsed -e 's/,/\n/g'           
foo
bar
baz

Alternatively, it is possible (though fiddly) to trick BSD sed into inserting newlines using extquotes.

  No Responses to “Inserting newlines with sed on OS X”

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)