You are not logged in.

#1 2007-11-18 12:13:01

jordanmthomas
Member
Registered: 2007-07-10
Posts: 33

[SOLVED] sed works in arch, but in os x it's different?

Hello, I have a quick question about sed and using newlines.

Say I have a file with one line in it like so:

va.artofwarcentral.com

I want to split each of the parts separated by periods into new lines.

I used sed to do this:

sed 's/\./\n/g' filename

and it works without incident.  The output is this:

va
artofwarcentral
com

However, when I try this on OS X I get this unexpected output:

vanartofwarcentralncom

Am I mistaken in thinking that the newline character in OS X is \n ?  I have tried several different escape characters, and they all give me back the same thing...it ignores the escape and just prints the character.

So, I guess my question is this:  am I doing something wrong or is this something that OS X is doing retardedly?  I know this might not be the best place to ask this since it's really more of an OS X question, but hopefully someone knows the answer.  I'm new to sed and regular expressions and all that jazz, so odds are I'm just doing something wrong.  Any help is appreciated.

Last edited by jordanmthomas (2007-11-18 12:35:56)

Offline

#2 2007-11-18 12:21:17

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [SOLVED] sed works in arch, but in os x it's different?

You are probably doing something wrong. After all, OS X uses some BSD implementation of sed, maybe even an Apple-centric implementation of it. So you're on your own there wink.

As you said yourself, the place to ask is some OS X-oriented forum, but not here.

Last edited by B (2007-11-18 12:22:19)


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#3 2007-11-18 12:35:37

jordanmthomas
Member
Registered: 2007-07-10
Posts: 33

Re: [SOLVED] sed works in arch, but in os x it's different?

Heh, sorry for posting it here.

Anyway, to get around the issue I have just separated it with spaces and used awk to get each word out, which seems to work on Arch and OS X.

So problem solved anyway now.

Offline

#4 2007-11-18 13:05:22

MrWeatherbee
Member
Registered: 2007-08-01
Posts: 277

Re: [SOLVED] sed works in arch, but in os x it's different?

jordanmthomas wrote:

Heh, sorry for posting it here.

Anyway, to get around the issue I have just separated it with spaces and used awk to get each word out, which seems to work on Arch and OS X.

So problem solved anyway now.

If you are still interested, there is some relevant information here (see Hal Itosis' post(s) especially):

http://forums.macosxhints.com/archive/i … 62778.html

Summary:

- update or change your version of sed
- use Perl
- use currently installed sed with some of the tricks supplied by Hal Itosis
- or stick with what you already did.

Offline

#5 2007-11-19 05:07:48

jordanmthomas
Member
Registered: 2007-07-10
Posts: 33

Re: [SOLVED] sed works in arch, but in os x it's different?

Many thanks, I'm glad it wasn't just me.  wink
I swear I looked everywhere too, but obviously not since you found the exact solution.

Offline

Board footer

Powered by FluxBB