Is there a fast way to change multiple links in a HTML file?

0

I have a HTML file containing the code for an image map with over 200 links, like this:

<area shape="RECT" coords="410, 7, 438, 35" href="/ItemDetails.jsp?item=os_landranger_1"/>

The problem is, the actual links are incorrect: I need to replace them with correct URLs, which are derived from a product title and reference number, which I have in a CSV file.

Essentially I need a specialised Find and Replace that will read the first link, get the title and ref. no. from the CSV, and enter them into the HTML in the correct format (i.e. with spaces replaced with _) before going onto the next one, and so on. The links need to come out the other end like this:

<area shape="RECT" coords="410, 7, 438, 35" href="product/1_-_Shetland_%C2%96_Yell%2C_Unst_and_Fetlar_9780319228074" />

In this case the title in the CSV would read '1 - Shetland - Yell, Unst and Fetlar' and the ref. no. would be 9780319228074

Is there any way I can do this, preferably for free?

EDIT:

I've managed to do this using Excel. I first imported the tags into a blank workbook as a CSV, telling Excel to use " as the delimiter. I then imported the title list into a new column and then reconstructed the tag in an empty cell with the & operator using the title list to replace the old URL. A bit of find and replace to convert commas and ampersands to HTML codes, then copying and pasting of the formula to the rest of the rows, and voila, success.

Thanks to everyone who answered.

ElendilTheTall

Posted 2011-06-02T13:54:16.973

Reputation: 21

What OS is your server running? *nix has utilities such as sed that could do this for you. – Chris Ting – 2011-06-02T13:56:21.153

The second is what the e-commerce system generates from the title and ref. no. entered during product creation. I am using Windows but have access to OS X if necessary. – ElendilTheTall – 2011-06-02T14:47:29.280

Answers

1

This is a pretty complicated search and replace. I personally don't know of any editor that can do this. How are the links in the page now correlated to the CSV file?

This is an easy thing to do in a script though. Its not hard to put together in a perl script (or python, whatever you prefer). Do you have scripting skills or know anyone who does?

Rich Homolka

Posted 2011-06-02T13:54:16.973

Reputation: 27 121

Managed to do it in Excel, see question. – ElendilTheTall – 2011-06-02T19:49:21.140

@ElendilTheTall interesting 'editor'. Thanks for the update. You should answer this yourself, and accept the answer (after the appropriate time period). – Rich Homolka – 2011-06-02T19:52:22.740

0

If they share an ordering system (or the csv can be ordered to fit what the current HTML file has), then you can use find and replace to replace href with ';', and then use text to columns to get the =... If your ordering is the same, you can then just replace the whole column (remember to add /> to the end of the line, and readd the href part. If there is no ordering scheme, based on what I can see (in the above provided sample), there is nothing you can do.

soandos

Posted 2011-06-02T13:54:16.973

Reputation: 22 744