Solved

Find / Replace escape

Posted on 2006-11-08
4
253 Views
Last Modified: 2008-02-01
Hello,

I want to do a find and replace on ALL files in a directory, using this:

       find /home/me/directory/ -type f | while read fname
       do
          sed 's/\FIND/REPLACE/g' $fname > $fname.new
         mv -f $fname.new $fname
       done



But I want to find this:
   <img src="images/my_image.jpg" width="150" height="50" hspace="5">


and replace it with this:
   <a href="link.name" target="_blank"><img src="image.gif" width="50" height="50" hspace="5" border="0" /></a>




What charactors to I need to escape and how do I escape them?


Thanks!
0
Comment
Question by:hankknight
  • 2
4 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 400 total points
Comment Utility
Hi hankknight,

You need to escape each speacial character with a \  ... field separator is also special character in a sed command, so use : instead of /  and you dont have to escape the / characters ...

sed 's:<img src="images/my_image.jpg" width="150" height="50" hspace="5">:<a href="link.name" target="_blank"><img src="image.gif" width="50" height="50" hspace="5" border="0" /></a>:g'

This should work ... Let me know the error if it fails

Cheers!
sunnycoder
0
 
LVL 16

Author Comment

by:hankknight
Comment Utility
Thanks,

What about each of these?  Which ones need escaping?

? \ . [ ] ^ $ & % \ _ > + = | !
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 100 total points
Comment Utility
\\  \. \[  \^  \$  
and perhaps \! depending on your shell
0
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
Look at the man page of sed on your machine ... that should contain the list of special characters

Cheers
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now