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 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.

share|improve this question
    
What OS is your server running? *nix has utilities such as sed that could do this for you. –  Chris Ting Jun 2 '11 at 13:56
    
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 Jun 2 '11 at 14:47

2 Answers 2

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?

share|improve this answer
    
Managed to do it in Excel, see question. –  ElendilTheTall Jun 2 '11 at 19:49
    
@ElendilTheTall interesting 'editor'. Thanks for the update. You should answer this yourself, and accept the answer (after the appropriate time period). –  Rich Homolka Jun 2 '11 at 19:52

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.

share|improve this answer

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.