The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace only 1st word of a line if it comes in the subsequent lines at same postion. geeko Shell Programming and Scripting 8 07-03-2008 04:24 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 07:24 AM
Search and replace multi-line text in files marz Shell Programming and Scripting 10 10-10-2005 05:05 AM
Replace line of text in a file colinchase UNIX for Dummies Questions & Answers 3 10-04-2001 06:54 AM
replace text in a file from the command line... dudboy UNIX for Dummies Questions & Answers 1 09-04-2001 11:31 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-18-2007
Registered User
 

Join Date: May 2005
Posts: 6
how to replace one line in text with several lines

Hi,
I need to replace a specific line in a text (eg the line contains the word MYSERVER) with a number of lines (let's say 4) in which the word MYSERVER will be replaced with
server1 in the first line
server2 in the second line
server3 in the 3rd line
server4 in the 4th line

The original text would be something like
lline1
line2
line3

THIS IS THE LINE WITH MYSERVER
line4
line5


The resulting text should be like:
lline1
line2
line3

THIS IS THE LINE WITH server1
THIS IS THE LINE WITH server2
THIS IS THE LINE WITH server3
THIS IS THE LINE WITH server4

line4
line5


If anyone could help with this it would be great!
Thank you.
Reply With Quote
Forum Sponsor
  #2  
Old 01-18-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
sed "/MYSERVER/c\\
THIS IS THE LINE WITH server1\\
THIS IS THE LINE WITH server2\\
THIS IS THE LINE WITH server3\\
THIS IS THE LINE WITH server4" file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0