Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find / Replace escape

Posted on 2006-11-08
4
Medium Priority
?
264 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 1600 total points
ID: 17896994
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
ID: 17898468
Thanks,

What about each of these?  Which ones need escaping?

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

Assisted Solution

by:ozo
ozo earned 400 total points
ID: 17900265
\\  \. \[  \^  \$  
and perhaps \! depending on your shell
0
 
LVL 45

Expert Comment

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

Cheers
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

971 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