【发布时间】:2021-07-01 09:04:36
【问题描述】:
假设我有以下类型的文件:
<?xml version="1.0" encoding="utf-8"?>
<preferences>
<section id="widgets">
<value id="version" xml:space="preserve">1</value>
</section>
<section id="wuid-b2a8e6b8-6619-714e-9cfe-466c27c90902">
<value id="path to widget data" xml:space="preserve">{Preferences}widgets/opera-adblock-1.3.4-1.oex</value>
</section>
<section id="wuid-0c5cfdb2-8e51-f149-a1e7-51d66240ed7a">
<value id="path to widget data" xml:space="preserve">{Preferences}widgets/flag-button-1.5.4-1.oex</value>
</section>
</preferences>
我的任务是在最后一次出现 </section> 之后添加文本。
看看这两个,似乎使用tac 会更简单,但我也不明白该怎么做:Using sed to append a string to the fourth occurrence of a pattern,http://www.unix.com/unix-dummies-questions-answers/46294-add-line-after-last-occurnace-pattern.html#post302149709
谢谢。
【问题讨论】:
-
为什么不在
</preferences>第一次出现之前添加呢? -
@Blender,嗯,因为我很愚蠢。那我该怎么做呢?
标签: sed