0
我发的文件的文件名匹配的数组中匹配模式:搜索和删除模式阵列的
lista=($(grep -El "<LastVisitedURL>.+</LastVisitedURL>.*<FavoriteTopic>0</FavoriteTopic>" *))
现在,我会删除一个文件INDEX.XML所有标签外壳包含在文件名阵列。
for e in ${lista[*]}
do
sed '/\<TopicKey FileName=\"$e\"\>.*\<\/TopicKey\>/d' index.xml
done
完整的脚本是:
#! /bin/bash
#search xml files watched and no favorites.
lista=($(grep -El "<LastVisitedURL>.+</LastVisitedURL>.*<FavoriteTopic>0</FavoriteTopic>" *))
#declare -p lista
for e in ${lista[*]}
do
sed '/<TopicKey FileName=\"$e\">.*<\/TopicKey>/d' index.xml
done
即使正则表达式模式行不通,在sed在地方INDEX.XML编辑-i
选项,重新加载索引文件多少次名怎么有数组,这是不好的。
有什么建议吗?
要编辑XML文件,使用'xmlstarlet' –
xmlstarlet是有用的。感谢Quenot和所有人。 – chuy