假设我有一个文件: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
但是它正在替换所有的_ to - present在line
使用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">