英文:
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! ]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论