Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
1) Embed a newline the old-fashioned way (this is good at the command-line, but not so much when doing this in a script);
Note that you have to basically press enter right after the backslash (some shells don't require a backslash).
Also, the ">" character is the default 'PS2' prompt (see the man page for ksh or bash).
xeleema @ SunOS $ echo "one,two,three" | sed -e 's/,/\
xeleema @ SunOS $
2) Use the 'tr' command if you are replacing just a single character;
xeleema @ SunOS $ echo "one,two,three" | tr ',' '\n'
xeleema @ SunOS $
Answer for "Why":
Early versions of 'sed' (and implementations that copied them) did not originally accept escaped characters in the Right-Hand-Side (RHS).
Information on this can be found in SourceForge's 'sed FAQ' online.
I've been unable to track down more information as to 'why' sed doesn't like dealing with '\n', I suspect Mr. McMahon might have been able to give us more guidance, had he not passed away in 1989.
The fact that sed has been around since about 1973 could have something to do with it.
I've seen older code with limitations built-in that reflected the current pre-existing limitations of various parts of an Operating system.
Once the Operating System improves, someone else has to go back and patch (or outright fork) the code and write-in improvements.
I'd imagine that's what the maintainers of GNU sed eventually wound up doing.