繁体   English   中英

在XML文档中使用sed或awk查找字符串并修改以下文本

[英]Use sed or awk to find string and modify text following within xml document

我试图在OS X上操作Adobe Reader plist文件以停止自动更新检查。 这需要编写脚本,这样我才能影响700多台Mac上的更改。

我有:

#!/bin/bash
plutil -convert xml1 /Users/username/Library/Preferences/com.adobe.Reader.plist

转换文件以进行文本编辑。

我在其他地方找到了此用于多行搜索和替换:

sed -n '1h;1!H;${;g;s/<h2.*</h2>/No title here/g;p;}' sample.php > sample-edited.php;

源文件具有相似数据的重复项,因此我需要在条目CheckForUpdatesAtStartup之后找到出现的位置

这是文件的一部分:

<key>AutoUriDetect</key>
                    <array>
                            <integer>0</integer>
                            <true/>
                    </array>
                    <key>CheckForUpdatesAtStartup</key>
                    <array>
                            <integer>0</integer>
                            <true/>
                    </array>
                    <key>CheckGPUAtStartup</key>
                    <array>
                            <integer>0</integer>
                            <false/>
                    </array>

因此,我需要将CheckForUpdatesAtStartup数组的true替换为false

awk > outfile '/CheckForUpdatesAtStartup/, /<(true|false)\/>/ {
  sub(/true/, "false")
  }1' infile

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM