You are not logged in.
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
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 .
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
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
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
Many thanks, I'm glad it wasn't just me.
I swear I looked everywhere too, but obviously not since you found the exact solution.
Offline