LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-25-2010, 08:28 PM   #1
snq
LQ Newbie
 
Registered: Feb 2009
Posts: 16

Rep: Reputation: 0
Replacement on more than one line in text files using Shell


How can I replace one instance of a word in a text file with a piece of text that spreads several lines ?

e..g I want to replace abcd123

with

Code:
abc1 fdsf
abe2 dfdfd 
asfs fdgdfg
asds  ytryt
you see the above spans multiple lines.

I know sed or awk is the way to go but don't know that how I can introduce new paragraphs using these tools

Last edited by snq; 11-25-2010 at 08:30 PM.
 
Old 11-25-2010, 08:33 PM   #2
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
Just use sed with \n:
Code:
sed 's/abcd123/abc1 fdsf\nabe2 dfdfd/' input_file

Last edited by quanta; 11-25-2010 at 08:36 PM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] open two text files , read them line by line and update parameters of the 3rd file rastin_nz Programming 17 10-20-2010 07:10 PM
[SOLVED] How to write a replacement for shell command line interpreter whirlpool Programming 8 09-06-2010 07:20 AM
join 2 text files based on first number present in every line of the 2 text files markraem Linux - Software 4 01-25-2010 06:26 AM
Delete line of text from text file via shell? zizou86 Programming 3 01-13-2010 11:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:21 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
Open Source Consulting | Domain Registration