Skip to content
Menu
HE'S BLOG
  • Home
  • One Page
  • Home page
  • Links
  • Mac
  • Windows
  • Program
  • AI
HE'S BLOG
2022年4月20日2022年4月20日

Shell sed 操作xml

shell sed 命令操作xml,有一个xml文件:a.xml

$ cat a.xml
<?xml version="1.0" encoding="UTF-8"?>
<Workflow>
  <Configuration>
        <Property Name="DataLine1" Value="" />
        <Property Name="DataLine2" Value="" />
  </Configuration>
</Workflow>

删除包含指定内容的行:删除 a.xml 中节中包含字符串: Name=”DataLine 的行,就是删除名字为 Name=”DataLineXXXXXX的行。

$ sed -i '/Name="DataLine/d' ./a.xml
$ cat a.xml
<?xml version="1.0" encoding="UTF-8"?>
<Workflow>
  <Configuration>
  </Configuration>
</Workflow>

使用shell sed 命令在指定的内容前添加一行新的内容:

$ export DataLine1='<Property Name="DataLine1" Value=""/>'
$ sed -i "/<\/Configuration>/i ${DataLine1}" ./a.xml 
$ cat a.xml
<?xml version="1.0" encoding="UTF-8"?>
<Workflow>
  <Configuration>
<Property Name="DataLine1" Value=""/>
  </Configuration>
</Workflow>

近期文章

  • Dify1.3.1安装
  • Gopro 驱动下载
  • Popular models download website
  • Stable diffusion enable remote access
  • Ollama remote access

近期评论

    归档

    • 2025 年 5 月
    • 2025 年 3 月
    • 2025 年 2 月
    • 2024 年 3 月
    • 2023 年 10 月
    • 2023 年 5 月
    • 2023 年 4 月
    • 2022 年 11 月
    • 2022 年 9 月
    • 2022 年 5 月
    • 2022 年 4 月
    • 2022 年 3 月
    • 2022 年 2 月
    • 2022 年 1 月
    • 2021 年 10 月
    • 2021 年 9 月
    • 2021 年 5 月
    • 2020 年 7 月
    • 2020 年 6 月
    • 2020 年 5 月
    • 2020 年 4 月
    • 2020 年 3 月
    • 2019 年 11 月
    • 2019 年 10 月
    • 2018 年 9 月
    • 2018 年 6 月
    • 2018 年 5 月
    • 2018 年 2 月
    • 2017 年 8 月
    • 2016 年 4 月

    分类

    • AI
    • Android
    • Angular
    • Apple Hardware
    • C++
    • Docker
    • Doctine
    • ELK
    • English
    • Hadoop
    • Hbase
    • IDE&Tools
    • Ionic2
    • Javascript
    • jQuery
    • Kubernetes
    • Mac
    • PHP
    • Program
    • Scala
    • Shell
    • SQL
    • Symfony
    • Web
    • Wordpress
    • 一行命令

    其他操作

    • 登录
    • 条目 feed
    • 评论 feed
    • WordPress.org
    ©2025 HE'S BLOG | Powered by WordPress and Superb Themes!