Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Check if this works for you

sed "s/images\\\/images\\//g"
share|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 '12 at 18:44

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
share|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 '12 at 19:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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