Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 3 down vote accepted

Check if this works for you

sed "s/images\\\/images\\//g"
share|improve this answer
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .