【问题标题】:how to edit and delete the xml attributes using shell script in mac如何在mac中使用shell脚本编辑和删除xml属性
【发布时间】:2020-08-10 10:10:31
【问题描述】:

我想用变量 $version-$date 编辑以下 xml 文件属性 ios-CFBundleversion 和 android-Versioncode 并删除版本属性或版本属性值?

<widget android-versionCode="20102" id="com.cricket.ade" ios-CFBundleVersion="20102" version="1.1" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>CreadApp</name>
    

这里 ios-CFbundleversion 和 android-versionCode 必须用 $version-$date 之类的变量替换,并且对于一个 xml 文件应该删除 version 属性,对于另一个 xml 文件应该删除 version 属性。

请帮帮我

【问题讨论】:

  • 您好!请添加具有预期输出的minimal and reproducible example
  • 尝试使用 xmllint 或 xmlstarlet 之类的 XML 解析器,如果您对尝试使用它们有疑问,请回复。请先查看How to Ask
  • 我同意 Ed Morton 的观点——要操作 XML 代码,不要使用 awk 和 sed 等纯文本工具;相反,使用专门为处理 XML 而开发的工具。我主要做 Oracle SQL,我无法告诉你有多少次人们试图用纯文本工具对 XML 代码做类似的事情......事情可能会以一千种不同的方式分解。

标签: xml shell awk sed


【解决方案1】:

我以前试过这个...它不起作用

sed -E 's/name="[^"]*"/ios-CFBundleversion="$VERSION-$SVNREV-$SVNDATE"/' config.xml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-26
    • 2016-08-10
    • 2022-01-01
    • 1970-01-01
    • 2013-07-09
    • 2016-12-27
    • 1970-01-01
    • 2012-01-20
    相关资源
    最近更新 更多