示例plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>file:http://ab.cd.com/path/path/:stable</key>
<dict>
<key>Distribution</key>
<string>stable</string>
<key>Sections</key>
<array>
<string>main</string>
</array>
<key>Type</key>
<string>deb</string>
<key>URI</key>
<string>http://ab.cd.com/path/path/</string>
</dict>
<key>file:http://xyx.domain.com/:./</key>
<dict>
<key>Distribution</key>
<string>./</string>
<key>Sections</key>
<array/>
<key>Type</key>
<string>deb</string>
<key>URI</key>
<string>http://xyx.domain.com/</string>
</dict>
<key>file:http://ab.domainCC.com/path/path/:stable</key>
<dict>
<key>Distribution</key>
<string>stable</string>
<key>Sections</key>
<array>
<string>main</string>
</array>
<key>Type</key>
<string>deb</string>
<key>URI</key>
<string>http://ab.domainCC.com/path/path/</string>
</dict>
<date>2015-04-18T13:51:58Z</date>
<string>2:8677bc80:5d017c133727de1493558fa4661586b70dfd0f65d8118b381dd76ab60bbe4548c0bfd008dc4314812a32b75d64c971b6</string>
<key>Values</key>
<dict/>
<key>Version</key>
<integer>1</integer>
</dict>
</plist>
项目的要求仅为“sed”。 这些是plist文件中的属性。我如何使用sed以
开头查找键值file:http://xyx.domain.com
并将其从那里删除
</dict>
最终结果将是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>file:http://ab.cd.com/path/path/:stable</key>
<dict>
<key>Distribution</key>
<string>stable</string>
<key>Sections</key>
<array>
<string>main</string>
</array>
<key>Type</key>
<string>deb</string>
<key>URI</key>
<string>http://ab.cd.com/path/path/</string>
</dict>
<key>file:http://ab.domainCC.com/path/path/:stable</key>
<dict>
<key>Distribution</key>
<string>stable</string>
<key>Sections</key>
<array>
<string>main</string>
</array>
<key>Type</key>
<string>deb</string>
<key>URI</key>
<string>http://ab.domainCC.com/path/path/</string>
</dict>
<date>2015-04-18T13:51:58Z</date>
<string>2:8677bc80:5d017c133727de1493558fa4661586b70dfd0f65d8118b381dd76ab60bbe4548c0bfd008dc4314812a32b75d64c971b6</string>
<key>Values</key>
<dict/>
<key>Version</key>
<integer>1</integer>
</dict>
</plist>
答案 0 :(得分:1)
尝试这种方式:
$ sed -e '/file:http:\/\/xyx.domain.com/,/<\/dict>/d' filename
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>file:http://ab.cd.com/path/path/:stable</key>
<dict>
<key>Distribution</key>
<string>stable</string>
<key>Sections</key>
<array>
<string>main</string>
</array>
<key>Type</key>
<string>deb</string>
<key>URI</key>
<string>http://ab.cd.com/path/path/</string>
</dict>
<key>file:http://ab.domainCC.com/path/path/:stable</key>
<dict>
<key>Distribution</key>
<string>stable</string>
<key>Sections</key>
<array>
<string>main</string>
</array>
<key>Type</key>
<string>deb</string>
<key>URI</key>
<string>http://ab.domainCC.com/path/path/</string>
</dict>
<date>2015-04-18T13:51:58Z</date>
<string>2:8677bc80:5d017c133727de1493558fa4661586b70dfd0f65d8118b381dd76ab60bbe4548c0bfd008dc4314812a32b75d64c971b6</string>
<key>Values</key>
<dict/>
<key>Version</key>
<integer>1</integer>
</dict>
</plist>