如何在一行HTML中将链接变成小写?

huangapple go评论105阅读模式
英文:

How to make just links lowercase in a line of HTML?

问题

我有几个包含数千个链接的大型HTML菜单文件,需要将它们全部转换为小写字母 - 但不更改其他部分。

整行的示例如下:

<li><strong><a href="pages\SDL_RenderDrawLine.htm">SDL_RenderDrawLine</a></strong> - draw a line.</li>

链接是唯一需要小写字母的部分... 实际上只需在引号之间的部分(如果这样更容易的话);但是,行的其余部分应保持不变。

<a href="pages\SDL_RenderDrawLine.htm">

"pages\SDL_RenderDrawLine.htm"

有什么高效的方法可以做到这一点?

感谢帮助(并帮我省了大量编辑的时间!)

英文:

I have several large HTML menu files that contain several thousand links that need to be made lowercase - but nothing else.

An entire line looks like this.

<li><strong><a href="pages\SDL_RenderDrawLine.htm">SDL_RenderDrawLine</a></strong> - draw a line.</li>

The link is the only part that needs to be lowercase... actually just the part between quote marks (if that makes it easier); but the rest of the line should remain untouched.

<a href="pages\SDL_RenderDrawLine.htm">

"pages\SDL_RenderDrawLine.htm"

What would be an efficient way to do this?

Thanks for the help (and saving me a ton of editing!)

答案1

得分: 0

我找到了一个不太优雅但有效的解决方法。

首先,我使用引号作为字段分隔符将字段(2)更改为小写。

awk 'BEGIN { FS = "\"\"" } {print ($1)"\"\""tolower($2)"\"\""$3}' test.txt > temp

这将链接(第二列)更改为小写。

[ 先前的问题已解决 - 在评论者的帮助下:...但不幸的是,移除了用作字段分隔符的引号 ' '。
然后,我手动使用文本编辑器搜索并替换引号 ' " ' 回到文件中。
我相信对awk更有经验的人知道如何在输出中保留字段分隔符,但这完成了工作! ]

英文:

Well, I found a workaround that is not elegant but works.

First, I changed field (2) to lowercase using quotes as the field separator.

awk 'BEGIN { FS = "\"" }  {print ($1)"\""tolower($2)"\""$3}' test.txt > temp

This made the links (2nd col) lowercase.

> [ Prior problem fixed - with help from commenter: ...but unfortunately removed the
> quotes ' " ' being used as a field separator.
>
> Then I manually used a text editor to search and replace the quotes '
> " ' back into the files.
>
> I am sure someone more experienced with awk knows how to keep the
> field separators in the output, but this got the job done! ]

huangapple
  • 本文由 发表于 2023年6月1日 02:27:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76376365.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定