Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-16-2010, 05:53 PM   #1
LQ Newbie
Registered: May 2010
Posts: 3

Rep: Reputation: 0
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:
I would like the output after i type the command to be
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?
Old 05-16-2010, 06:19 PM   #2
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
The following should work
sed -e :a -e ';$!N;s/\n/\\n/;ta' file
Old 05-16-2010, 06:27 PM   #3
LQ Newbie
Registered: May 2010
Posts: 3

Original Poster
Rep: Reputation: 0
UGH! you sir are a saint. Thanks a million!
Old 05-17-2010, 09:03 AM   #4
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
simple sed question faizlo Programming 2 01-20-2009 08:45 PM
simple sed question jaykup Programming 3 02-25-2008 02:23 AM
Simple question about sed or awk setianusa Programming 2 09-16-2005 04:57 PM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 03:55 AM
using sed, simple question bobthebat Programming 3 04-30-2001 11:01 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:10 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration