[英]sed: replace _ within quotes with -
假設我有文件:index.html
index.html
<div class="familylinks">
<div class="parentlink"><strong>Parent_topic:</strong> <a class="link" href="../some_text_here_a_b" title="Sample html Page here">Sample_html_page</a></div>
</div>
</div><div class="runningfooter" align="center">
我如何將 _ 替換為 - 在 href="../some_text_here_a_b" 中(href 的雙引號)
例如,將 index.html 更改為:
<div class="familylinks">
<div class="parentlink"><strong>Parent_topic:</strong> <a class="link" href="../some-text-here-a-b" title="Sample html Page here">Sample_html_page</a></div>
</div>
</div><div class="runningfooter" align="center">
試過,
sed -e "/href/s/_/-/g" index.html
但它正在將所有 _ 替換為 - 出現在在線有 href 字的在線
使用sed
$ sed -E ':a;s/(href="[^"]*)_/\1-/;ta' input_file
<div class="familylinks">
<div class="parentlink"><strong>Parent_topic:</strong> <a class="link" href="../some-text-here-a-b" title="Sample html Page here">Sample_html_page</a></div>
</div>
</div><div class="runningfooter" align="center">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.