【问题标题】:sed command - remove all commas from text between HTML tagsed 命令 - 从 HTML 标记之间的文本中删除所有逗号
【发布时间】:2017-07-31 04:01:13
【问题描述】:

请有人帮忙。我需要在命令行中从特定的 HTML 标记(如 和 )中查找并删除逗号,但只能从此标记中查找和删除逗号。

例子:

...    
<h3>Sample header, with some, text with commas</h3>
<h4>Sample header, with some, text with commas</h4>

<p>Loreipsum sit amet, dolor...</p>
...  

我使用:

sed "/<h3>/,/<\/h3>/s/,//g"

但是这个命令从所有代码中删除逗号...我只需要

标记。

【问题讨论】:

    标签: linux bash ubuntu sed terminal


    【解决方案1】:

    你可以试试这个

    sed -e '/<*>/s/,/ /g' stack4.html
    

    在stack.html下面的字符串是写的

    <h3>Sample header, with some, text</h3>
    Hi, what's your namiue
    <h3>Sample header, with some, text</h3>
    <h3>Sample header, with some, text</h3>
    hyt,ujt,yj
    <h3>Sample header, with some, text</h3>
    jkj<h3>Sample header, with some, text</h3>
    

    o/p 我明白了

    <h3>Sample header  with some  text</h3>
    Hi, what's your namiue
    <h3>Sample header  with some  text</h3>
    <h3>Sample header  with some  text</h3>
    hyt,ujt,yj
    <h3>Sample header  with some  text</h3>
    jkj<h3>Sample header  with some  text</h3>
    

    如果你只想为 h3 和 h4 做,那么下面的命令可能会对你有所帮助

     sed -e '/<h[3-4]>/s/,/ /g' stack4.html
    

    希望它会起作用:)

    【讨论】:

    • 感谢您的回答,但不幸的是,您的命令从所有 html 标记中删除了逗号。我只需要从

      中删除逗号,其他标签必须完好无损。

    猜你喜欢
    • 1970-01-01
    • 2022-06-23
    • 2015-12-20
    • 2018-02-08
    • 2020-02-20
    • 1970-01-01
    • 2021-07-03
    • 2011-10-08
    • 2015-08-12
    相关资源
    最近更新 更多