Suppose I have a standard Word document called document.doc
.
Inside this document, there are hyperlinks to some server which no longer exists. I wish to replace the link with the aproper one, and since I must do this to many files, I hope there is a way to automate it.
How can I change the hyperlink to something else from outside Microsoft Office? Preferably in a Linux/Unix environment.
I noticed that all the hyperlinks in the document are stored in plaintext and can be viewed by
strings document.doc | grep -i "hyperlink"
I therefore tried a simple sed
approach like this to edit in place:
sed -ir 's/www.badlink.com/www.goodlink.com/' document.doc
I then confirmed the hyperlink had changed by calling strings
again. However, after using sed
, the document cannot be opened by MS Word -- it states the file is corrupted.
So, is there any easy way to edit links in an Microsoft Word document by Linux/Unix tools? In the worst case, I imagine the task can be done with some Microsoft Office macro. And that is okay, too, if it is the only possibility.