The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Newlines in shell variables narcvs Shell Programming and Scripting 5 03-26-2009 02:54 AM
sed problem replacing long strings mark007 UNIX for Dummies Questions & Answers 1 11-28-2008 12:02 AM
replacing comma's with newlines using sed newbie_coder Shell Programming and Scripting 5 09-29-2008 12:44 AM
replacing strings with text from other file mc1392 Shell Programming and Scripting 1 03-24-2008 03:46 PM
Newbie: replacing strings containing special caracters drumkid UNIX for Dummies Questions & Answers 1 04-03-2006 03:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-28-2008
hkansal hkansal is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 69
replacing strings with newlines : sed

Hi everyone,

Since the previous time I received help from unix.com I have been encouraged to learn more.

going through 1 of the articles(View Article) on sed I found, it pointed an interesting situation.
Suppose the text is :

Romeo and Ethel the Dancer Moves Audience to Tears.
I was treated to the off Broadway opening of Romeo and Ethel the
Dancer. This moving story of star-crossed lovers had the
audience in tears half way through the third act.
Do not go to see this play without a hanky, but even the weeping
from the back row could not diminish the brilliance of Romeo and
Ethel the Dancer by William Shakespeare.


Now I want to replace "Romeo and Ethel the Dancer" by "Romeo and Juliet".
The lines are separated by newlines.

The article demontrates doing this by using addresses. I was trying to think of another way round by building a reg-ex and use simple sed.
I believe I need a way to represent a newline in the sed search expression.

Please help by hinting towards the solution and not directly.

Thank You.

Regards

Last edited by hkansal; 11-28-2008 at 01:27 PM.. Reason: Added link back to original article
  #2 (permalink)  
Old 11-28-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink

One approach might be to replace all new-line characters with a different character. Perhaps

tr "\n" "~" would turn the text into one long string
  #3 (permalink)  
Old 11-28-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Or have a look into sed's abilities for multiline pattern (N).
  #4 (permalink)  
Old 11-28-2008
hkansal hkansal is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 69
Thanks for the options, I ll try these out and get back to you.

Regards
Closed Thread

Bookmarks

Tags
multiline, sed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0