0

私はこのようなhtmlコードを持っています

<a href="/site/index.php/Something" title="Something">Something cool</a>, <a href="/site/index.php/Nice_Text" title="Nice Text">Nice Text</a>
some text
<a href="/site/index.php/Apple%27s_text" title="Apple's text">Apple's text</a>

これを取得するには、リンクにドット (先頭) と .html (末尾) を追加する必要があります。

<a href="./site/index.php/Something.html" title="Something">Something cool</a>, <a href="./site/index.php/Nice_Text.html" title="Nice Text">Nice Text</a>
some text
<a href="./site/index.php/Apple%27s_text.html" title="Apple's text">Apple's text</a>

私はsedで遊んでいましたが、変更されたURLを操作する方法がわかりません。そのプットの前(または変数間の後)を探して"/site/index.php/最初に出現するようなもの。"".html

ありがとうございました。

4

2 に答える 2

1
sed 's/<a \+href="\([^\"]*\)"/<a href=".\1.html"/g' my_file.html

これは、のように見えるものを探し、を<a href="xxx"に置き換えます。と の間に複数のスペースを入れることができます。を見つけるために、を含まない任意の文字列を探します。これは、例が示すように元のファイルに先行が含まれていること、およびすべてがファイル内の同じ行にあることを前提としています (たとえば、との間で壊れていません)。このオプションは、1 行で複数の を確実に処理するようにします。xxx.xxx.htmlahrefxxx""/<a href="xxx"ahrefghref

于 2013-09-01T10:24:28.697 に答える
0

awk の使用

awk '{gsub(/href="/,"&.");gsub(/" title/,".html&")}1' file
于 2013-09-01T16:09:07.200 に答える