我正在使用 Shell 脚本
Config.xml
我在文件中有以下内容
<Example>
<Parameter Name="hello" Time="hello" Time="hello" Conf="1" example="0" Attribute="hello">
MO
</Parameter>
<Parameter Name="hello" Time="hello" Time="hello" Conf="0" example="1" Attribute="hello">
hiaaa
</Parameter>
<Parameter Name="hello" Time="hello" Time="hello" Conf="1" example="1" Attribute="hello">
youhoo
</Parameter>
<Integer Name="hello" Time="hello" Time="hello" Conf="0" example="1" Attribute="hello">
10
</Integer>
<Parameter Name="hello" Time="hello" Time="hello" Conf="1" example="0" Attribute="hello">
Receive
</Parameter>
<Parameter Name="hello" Time="hello" Time="hello" Conf="1" example="0" Attribute="hello">
reporttt
</Parameter>
<Integer Name="hello" Time="hello" Time="hello" Conf="1" example="1" Attribute="hello">
10
</Integer>
<Integer Name="hello" Time="hello" Time="hello" Conf="1" example="1" Attribute="hello">
</Example>
我运行以下 shell 代码来摆脱Name
属性
awk '{ {if ($2 ~ "^Name*") $2=""}; print $0}' Config.xml > myConfig.xml
我确实摆脱了Name
属性,但得到了以下输出
<Example>
<Parameter Time="hello" Time="hello" Conf="1" example="0" Attribute="hello">
MO
</Parameter>
<Parameter Time="hello" Time="hello" Conf="0" example="1" Attribute="hello">
hiaaa
</Parameter>
<Parameter Time="hello" Time="hello" Conf="1" example="1" Attribute="hello">
youhoo
</Parameter>
<Integer Time="hello" Time="hello" Conf="0" example="1" Attribute="hello">
10
</Integer>
<Parameter Time="hello" Time="hello" Conf="1" example="0" Attribute="hello">
Receive
</Parameter>
<Parameter Time="hello" Time="hello" Conf="1" example="0" Attribute="hello">
reporttt
</Parameter>
<Integer Time="hello" Time="hello" Conf="1" example="1" Attribute="hello">
10
</Integer>
<Integer Time="hello" Time="hello" Conf="1" example="1" Attribute="hello">
</Example>
我希望输出是这个
<Example>
<Parameter Time="hello" Time="hello" Conf="1" example="0" Attribute="hello">
MO
</Parameter>
<Parameter Time="hello" Time="hello" Conf="0" example="1" Attribute="hello">
hiaaa
</Parameter>
<Parameter Time="hello" Time="hello" Conf="1" example="1" Attribute="hello">
youhoo
</Parameter>
<Integer Time="hello" Time="hello" Conf="0" example="1" Attribute="hello">
10
</Integer>
<Parameter Time="hello" Time="hello" Conf="1" example="0" Attribute="hello">
Receive
</Parameter>
<Parameter Time="hello" Time="hello" Conf="1" example="0" Attribute="hello">
reporttt
</Parameter>
<Integer Time="hello" Time="hello" Conf="1" example="1" Attribute="hello">
10
</Integer>
<Integer Time="hello" Time="hello" Conf="1" example="1" Attribute="hello">
</Example>
有什么帮助吗??