【发布时间】:2012-09-07 22:57:27
【问题描述】:
我想写一个在终端中执行的脚本。
我正在编辑 xml 文件,我想在检测到 xml 列的头部后添加一个或多个字符串..
这是一个示例 xml
bunch of line
more unimportant lines
and they can very in number
<States>
<item1> something something </item1>
<item2> something something </item1>
<item3> something something </item1>
</states>
现在我想添加一个项目 4。但是,我希望将它插入到项目 1 之前。
理想情况下,文件应如下所示:
bunch of line
more unimportant lines
and they can very in number
and even some lines were added here
and here
and here
<States>
<item4> something something </item1>
<item1> something something </item1>
<item2> something something </item1>
<item3> something something </item1>
</states>
请注意,顶部添加了与代码无关的其他内容。这些是即将进入的cmets。
我愿意在 perl 中这样做,但 shell 会更好。
【问题讨论】:
-
<item2> ... </item1>对吗...?看起来不像是有效的 xml。 -
我推荐一个 XML 解析器,其中大部分应该能够在某个范围内注入新元素
标签: perl bash shell unix terminal