2017-03-27 66 views
0

我需要删除/修改从HTML文件的Bash shell - 内标签更改文本和删除标记内

一些内容,从这一个我需要删除一切,从div标签,直到的beggining全部内容/ DIV结束

<div id="footer" role="contentinfo"> 
 
    <section class="footer-body"> 
 
     <p>Document generated by Confluence on 2017/03/27 09:41</p> 
 
      <div id="footer-logo"> 
 
       <a href="http://www.atlassian.com/">Atlassian</a></div> 
 
    </section> 
 
      </div>

在这里,我需要改变的作者和编辑的姓名

Created by <span class='author'>John Smith</span>, last modified by <span class='editor'> John Smith</span> on 2017/03/24

我知道我需要用sed,但我不知道如何创建所述表述

+1

在第一个样品输入你有两个嵌套的div标签。你需要删除哪一个?嵌套有多深?两个嵌套的div标签是最大的吗?在这一点上,这种解读是误导性的。什么强迫你使用sed?如果不是合适的XML/HTML解析器,几个注释将推荐使用至少awk。你也可能会发现评论询问你试过的东西,错过了你已经完成了某些sed手动阅读和一些简单实验的印象。有一些关于如何提出一个好问题的帮助。 – Yunnosch

+0

例如这里:http://stackoverflow.com/help/how-to-ask – Yunnosch

回答

0

关于到第一挑战请更具体。

这是第二个挑战sed脚本:

source="Created by <span class='author'>John Smith</span>, last modified by <span class='editor'> John Smith</span> on 2017/03/24" 
author="new author" 
editor="new editor" 
result=`echo "$source" | sed "s/\(.*author'>\).*\(<\/span>,.*editor'>\).*\(<\/span.*\)/\1$author\2$editor\3/"` 

echo $result