LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 01-20-2009, 11:27 PM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
Multiple search and replace


Hi all,


I can use
Code:
sed −e 's/erors/errors/g' −e 's/last/final/g' example
to multiple search and replace.

We can use

Code:
 sed -i 's/erors/errors/g' example
to do a permanent replacement. My question is how to do a multiple search and replace using sed -i .


Thanks

Last edited by ZAMO; 01-21-2009 at 02:14 AM. Reason: change the heading
 
Old 01-21-2009, 04:08 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Code:
sed -i.bak −e 's/erors/errors/g' −e 's/last/final/g' example
It will create the file example.bak where the old (unmodified) version will be.
 
Old 01-21-2009, 11:02 PM   #3
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Sycamorex,

Thanks for your reply.
Code:
sed  −e 's/erors/errors/g' −e 's/last/final/g' example >newfile

we can do this , but we need to write to a new file. I want to do a find and replace the string, keeping the files as it is.

Any idea.

Thanks
 
Old 01-22-2009, 02:01 PM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Ok, this is probably not the most elegant way, but it works:
Code:
find . -name example -exec sed -i −e 's/erors/errors/g' −e 's/last/final/g' {} \;

Last edited by sycamorex; 01-24-2009 at 04:57 AM.
 
  


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
how do I search for multiple filetypes? fisayo Linux - General 4 07-19-2005 07:05 AM
search and copy multiple files NiallC Programming 2 04-29-2005 04:40 AM
Search and Replace over multiple files The_Nerd Linux - Software 8 06-20-2004 06:59 AM
multiple search on mysql gmarais Programming 3 03-10-2004 08:59 AM
multiple file search llimllib Linux - Software 2 02-10-2003 03:25 AM

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

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