LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 03-02-2014, 08:37 AM   #1
neon99
LQ Newbie
 
Registered: Mar 2014
Posts: 4

Rep: Reputation: Disabled
Replacing text on multiple lines


Hello all,

I am trying to replace text in files which looks like below

a
b

I am using find command as below to replace it by 'c'

find ./ -type f -exec sed -i 's/a\nb/c/' {} \;

Its not working.

Please help.
 
Old 03-02-2014, 09:43 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 840

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
You can not match multiline expressions in sed like this. You'll need something like

Code:
 sed -i '/a/{N;s/a\nb/c/}'
 
Old 03-04-2014, 10:17 AM   #3
neon99
LQ Newbie
 
Registered: Mar 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks a lot. It worked.
 
Old 03-06-2014, 10:13 AM   #4
neon99
LQ Newbie
 
Registered: Mar 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi Again,

Now I am trying to replace text in files which looks like below

a
b
c

I want to replace this by

1
2
3
 
Old 03-06-2014, 10:47 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Show us your code; we're here to help, not do it for you.
 
Old 03-07-2014, 10:54 AM   #6
neon99
LQ Newbie
 
Registered: Mar 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Here is what I am using

find ./ -type f -exec sed -i '/a/{N;s/a\nb/c/}' {} \;
 
  


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
[SOLVED] Sed - Replacing only text with several specific lines excluded Potatos Linux - Newbie 6 06-18-2010 12:51 AM
Replacing text on specific lines with sed or awk? Lantzvillian Linux - Newbie 5 10-17-2007 10:00 AM
Replacing multiple lines with null aress Linux - General 3 03-06-2007 09:47 AM
replacing specific lines in a text document stellarmarine1 Linux - General 1 09-07-2004 03:34 PM

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

All times are GMT -5. The time now is 08:52 AM.

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