LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 05-16-2010, 04:53 PM   #1
e64462
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:
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?
 
Old 05-16-2010, 05:19 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,823
Blog Entries: 1

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
The following should work
Code:
sed -e :a -e ';$!N;s/\n/\\n/;ta' file
 
Old 05-16-2010, 05:27 PM   #3
e64462
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, 08:03 AM   #4
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

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


Reply


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 07:45 PM
simple sed question jaykup Programming 3 02-25-2008 01:23 AM
Simple question about sed or awk setianusa Programming 2 09-16-2005 03:57 PM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
using sed, simple question bobthebat Programming 3 04-30-2001 10:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:44 PM.

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