LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   simple sed question (https://www.linuxquestions.org/questions/linux-newbie-8/simple-sed-question-808208/)

e64462 05-16-2010 04:53 PM

simple sed question
 
I've been searching for a while now, but everything I've found wants to do the exact opposite of what I need.

I'm looking to replace all newlines in a file with the actual "\n" string.

So, for example. If my file contained:
Quote:

one
two
three
I would like the output after i type the command to be
Quote:

one\ntwo\nthree
Most of the help I've found is to do the exact opposite. I've tried tr and sed, but I'm not abundantly familiar with regex does anyone have a suggestion?

sycamorex 05-16-2010 05:19 PM

The following should work
Code:

sed -e :a -e ';$!N;s/\n/\\n/;ta' file

e64462 05-16-2010 05:27 PM

UGH! you sir are a saint. Thanks a million!

SuperJediWombat! 05-17-2010 08:03 AM

http://linux.dsplabs.com.au/rmnl-rem...-sam-ssam-p65/


All times are GMT -5. The time now is 02:59 PM.