【发布时间】:2010-01-20 15:51:09
【问题描述】:
我有一个如下格式的列表
77 Infinite Dust
4 Illusion Dust
12 Dream Shard
29 Star's Sorrow
我需要将其更改为:
77
<a href="http://www.wowhead.com/?search=Infinite Dust">Infinite Dust</a>
4
<a href="http://www.wowhead.com/?search=Illusion Dust">Illusion Dust</a>
12
<a href="http://www.wowhead.com/?search=Dream Shard">Dream Shard</a>
29
<a href="http://www.wowhead.com/?search=Star's Sorrow">Star's Sorrow</a>
我已经设法将这个列表变成了正确的格式,只是缺少了数字:
sed 's|^[0-9]*.|<a href="http://www.wowhead.com/?search=|g' filename | sed 's|$|">|g' | sed 's#<a[ \t][ \t]*href[ \t]*=[ \t]*".*search=\([^"]*\)">#&\1</a>#'
但我不知道如何让它保持列表前的数字,任何帮助表示赞赏,谢谢!
【问题讨论】:
-
您在标签中提到了 sed 和 awk,但没有理由避免使用 perl。由于您也提到了 linux,因此您不太关心可移植性,并且几乎所有主要发行版(如果不是全部)都将包含 perl 解释器……那么为什么不使用它呢?
-
我没有 perl 经验,但我相信它做得非常好!