自动文本替换的最佳方法是什么?

发布于 2024-07-30 09:43:26 字数 263 浏览 11 评论 0原文

情况是这样的:

我有很多 HTML 文件,这些 HTML 文件链接到很多文档。 这些文件已全部重命名。 我有一个 Excel 工作表,其中包含文件的旧名称和新名称。

更改 HTML 文件内的链接以适应新名称的最快方法是什么?

我现在使用的方法: 在 Notepad++ 中打开所有 HTML 文件 使用Notepad++的“在所有打开的文档中替换”功能可以用新文件名替换所有出现的特定链接。

有没有更快、更好的方法?

Here's the situation:

I have a lot of HTML files, and these HTML files link to a lot of documents. The documents have ALL been renamed. I have an excel sheet which has the old name of the file and the new name of the file.

What would be the quickest way to change the links inside the HTML files to accommodate the new names?

The method I'm using now:
Have all the HTML files opened in Notepad++
Use Notepad++'s 'Replace in All Opened Documents' function to replace all occurrences of a certain link with the new file name.

Is there a quicker, better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

流殇 2024-08-06 09:43:26

Perl 的正则表达式。

阐述:
伪代码

open up each file for read-only and read them into a list.
close the files
foreach element in the list
#do the desired text replacement
`s/$oldtext/$newtext/g`;
open each file once more now for writing
write out the new text.

并不难,但需要一些测试。 如果您有大量编辑(并且稍后可能会发生更多编辑),那么这会更有效。

Perl's regular expressions.

elaboration:
pseudocode

open up each file for read-only and read them into a list.
close the files
foreach element in the list
#do the desired text replacement
`s/$oldtext/$newtext/g`;
open each file once more now for writing
write out the new text.

It's not hard, but requires some testing. If you have a lot of edits(and more may happen later), this is more efficient.

画中仙 2024-08-06 09:43:26

有几种免费的开源工具可以替换多个文件中的文本,其中一个开源工具是 FART

如果您更喜欢 GUI 的功能,请尝试免费的文本爬虫

There are several free and open-source tools that replace text in several files, one of the open-source ones is FART

If you prefer something with a GUI, try the free Text Crawler

ゃ人海孤独症 2024-08-06 09:43:26

首先将 Excel 保存到一些漂亮且简单的文件(例如 csv 文件)中,以便可以轻松地用您喜欢的语言(例如 perl)阅读。 迭代每个文件并进行搜索和替换。 不过,一个问题是一次性完成所有操作,否则如果链接以复杂的方式发生了变化,您可能会产生问题。 即,如果文件 a.html 更改为 b.html 并且 b.html 更改为 a.html,则如果您多次执行此操作,则可能会弄乱链接。 因此,将所有更改加载到内存中,然后循环遍历每个文件并同时替换其中的所有链接。

因为它是专门的 html 搜索和替换,像这样的工具将是理想的:

http://www.aliassoftware.com/< /a>

一次查找并替换多个文件中的多个文本字符串!

First save the excel to somethine nice and simple like a csv file so its easy to read in you favourite language eg perl. Iterate over each file and do the search and replace. One gotcha though is to do it all in one pass otherwise you could create problems if there are links that have changed in complex ways. Ie if file a.html changed to b.html and b.html changed to a.html you can mess up the links if you do it in multiple passes. So load all the changes into memory then cycle through each file and replace all links in it simultaneously.

Because it is specifically html search and replace a tool like this would be ideal:

http://www.aliassoftware.com/

Finds and Replaces multiple text strings in multiple files at once !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文