: :

Add Comment | Related Links | TrackBack
Related Content

sed won't produce new line on Mac OS X

Discovered a problem with 'sed' UNIX command on Mac OS X tonight. I want to use it to parse text and position new line characters in the right place in the sequence. But the 'sed' program that is on Mac OS X doen't work correctly. Instead of adding new line characters, it strips the backslash and output the 'n' character. The following is an example from the Mac OS X Terminal:

  $ echo "Hello World" | sed 's/World/\nWorld/'
Hello nWorld

The same example works correctly on Ubuntu Linux:

  $ echo "Hello World" | sed 's/World/\nWorld/'

Is there an alternative solution. I would like to get this to work on Mac OS X. For now, I can fall back to Ubuntu Linux, but it's more work. Anyone have a work-around?

Chieh Cheng
Sun, 18 Jul 2010 08:15:54 +0000

Same identical problem! Didi you sort it out?

Wed, 04 Aug 2010 12:47:40 +0000

Unfortunately, no. My only work-around now is to transfer the file to Ubuntu Linux, process it, and then transfer it back. :-(

Chieh Cheng
Wed, 04 Aug 2010 15:44:33 +0000

TRye this out: . . .

$ echo 'foo bar baz quux' | sed -e 's/ /\'$'\n/g'

Mon, 06 Jun 2011 13:07:58 +0000

Thanks, zharik. It works on both Mac OS X and Ubuntu Linux.

Chieh Cheng
Thu, 02 May 2013 21:46:57 +0400

Add Comment | Related Links | TrackBack
Related Content

Did your message disappear? Read the Forums FAQ.


TrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites.

Send Ping | TrackBack URL | Spam Control

Title: egrep ignores begin of line on Mac OS X
Weblog: GearHack
Excerpt: Darwin UNIX commands doesn't always seem to follow standard rules, such as the "sed won't produce new line on Mac OS X " issue. I just found another exception: $ echo "Contagion" egrep -o '^.' C o n t a g i o n It's not suppose to do that. It completely ignored the beginning line character in the . . .
Tracked: Fri, 20 Jan 2012 03:39:08 +0300

Add Comment

Spam Control | * indicates required field
Your Name: *
Remember Me!
Comment: *
File attachment is optional. Please do not attach a file to your submission unless it is relevent.
Attach File:
(20 MB Max)
Spam Protection: * Answer of 8 + 4?
Click button only once, please!

Messages, files, and images copyright by respective owners.

Articles | Wiki
Forums | Latest | RSS
Library | Links | News
Search | Store | Help

148 Users Online

Hacking Digital Cameras
Fun for Photographers

Amazon Associate

Copyright © 2004 - 2024. All Rights Reserved.