I've got a bunch of html files, and all the img tags have the slashes the wrong way!

Here's an example (except it's one line in the code, split here for ease of viewing)

<a href=index.html><img src="images\homereg.png" /></a>
<img src="images\spacer.png" />
<a href=dogs.html><img src="images\dogsreg.png" /></a>
<img src="images\spacer.png" />
<a href=litters.html><img src="images\littersreg.png" /></a>
<img src="images\spacer.png" />
<a href=bredby.html><img src="images\bredbyreg.png" /></a>
<img src="images\spacer.png" />
<a href=contact.html><img src="images\contactreg.png" /></a>

My problem with what I've tried so far is that sed is greedy, so it's matching too much and not replacing it properly. Something like sed -i 's|images\\\(.*\)\"|images/\1\"|g' * will replace one per line, it's matching too much. I've tried some other things, but all along the same line as this.

What's the easiest solution? I'm not limited to sed, I just know it best so it's what I've tried.

link|improve this question

feedback

2 Answers

up vote 2 down vote accepted

Check if this works for you

sed "s/images\\\/images\\//g"
link|improve this answer
1  
OH MY GOD. I took the problem way too far. This was so simple. Thanks! sed 's|images\\|images/|g' – Rob Jan 23 at 18:44
feedback

Don't use regular expressions. Just replace all occurrences of images\ with images/.

All basic text editors should support that.

If you want to use sed:

sed 's|images\\|images/|g' filename.html
link|improve this answer
Yeah, I didn't even think of that. :( Now if only my girlfriend remembered when I told her the files were case sensitive. Having to go through each page and fix broken images. – Rob Jan 23 at 19:03
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.