[英]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.