We're taking over another company's website and we plan on creating an archived version of their old site using wget to mirror the site into an archive.example.com website.

Since there are several year's worth of articles and stories and a considerable amount of stories still in Google, we are planning on 301'ing as many of the urls as we can and replacing their old defunct ad code with new DFP tags.

Any thoughts on how to replace thousands of old JS ad tags in a directory full of static html pages?

  • Sorry but this question is opinionated as there are many ways that this can be done. Commented Jun 4, 2018 at 20:43
  • Example: powershell, ssh, editors (notepad+, sublime, brackets) httrack, SFTP clients, FTP clients... All answers would be correct based on your question, hence opinionated, all are right, some are better than others, subjectively. Commented Jun 4, 2018 at 20:50
  • 1
    Just because there can be multiple answers doesn't mean it's opinion. The answers themselves either work or do not work. Answers to this question can in fact be answered through facts, references or specific expertise.
    – Dan Gayle
    Commented Jun 4, 2018 at 20:50
  • It should also be noted that while the question has a 'website' feel to it, it's actually more of an operating system/application since find and replace is no different on an HTML file than it is to a CVS or TXT file. You will most likely find related questions on SuperUser or if you require variables (regex) then Stack Overflow. Commented Jun 4, 2018 at 21:29

1 Answer 1


Some text editors, including Notepad++, have a "find in files" search and replace option. You tell it what directory to search, what string to search for (can be regex or just plain text), and what to replace it with (if anything). This would work on a local copy which you'd then need to upload. You might want to replace it with simple Google Tag Manager code, which would then allow you to manage all the scripts from one dashboard (change in one place, it changes everywhere) so you don't have to go through this again.

If you have SSH access to the server, you could also (after backing up) run a command to search and replace across files.

In either case it's more complicated if the code is not exactly the same from page to page - i.e. sometimes it's indented, other times not, sometimes multi-line, which is where the regex options may come in quite handy.

  • The original website is on a terrible hosted solution, so I don't think I have access to pre-edit the ad code. You're right though, it would be a great way to handle it otherwise.
    – Dan Gayle
    Commented Jun 4, 2018 at 20:41
  • Your using wget yet you have no access? ... perfectly good answer based on your question. Commented Jun 4, 2018 at 20:45
  • Do you even know what wget is?
    – Dan Gayle
    Commented Jun 4, 2018 at 20:51
  • Yes? Why wouldn't you have access to these files? since you obviously have command line access on the external server. Then... you just sshfs (SFTP) or FTP mount the drive on your workstation and use Notepad++ as advised. As I said a perfectly good answer and one of many that can be provided, none more right than the next. An opinionated question as an I said previously, but thank you for attempting to make me look stupid with the wget comment. Commented Jun 4, 2018 at 21:07
  • I am using WGET to grab an external website that I have limited control over. Your question was "You're using wget yet you have no access," the answer to which is yes, I am using wget BECAUSE I have no access. Not trying to make you look stupid. But your concept of opinion as regards to proper questions and answers is flawed. There are slots here for multiple answers. Multiple different answers to the same question is a good and helpful thing, none of which have to be opinion based answers. Just factual answers. How do I do this, here are X number of ways. No opinions necessary or wanted.
    – Dan Gayle
    Commented Jun 4, 2018 at 21:46

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