【问题标题】:Delete HTML code from log file in SHELL从 SHELL 中的日志文件中删除 HTML 代码
【发布时间】:2014-02-20 17:38:09
【问题描述】:

我有一个包含 html 代码的日志文件,我需要删除该文件中每个可能匹配项的 html 标记之间的所有内容。使用过滤器怎么可能?

我的文件示例:

some text here
<html>
code
</html>
some text there
<html>
code
</html>
some other text

输出应该是:

some text here
some text there
some other text

【问题讨论】:

    标签: bash sed awk grep


    【解决方案1】:

    这个awk 应该这样做:

    awk '/<html>/{f=1;next} !f; /<\/html>/{f=0}' file
    some text here
    some text there
    some other text
    

    【讨论】:

      【解决方案2】:

      为什么不只是:

      sed '/<html>/,/<\/html>/d'
      

      它适用于您的示例。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-01-07
        • 2010-10-14
        • 2013-06-11
        • 2012-05-05
        • 2018-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多