Sed: append after last occurrence -



Sed: append after last occurrence -

let's have next kind of file:

<?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 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 widget data" xml:space="preserve">{preferences}widgets/flag-button-1.5.4-1.oex</value> </section> </preferences>

my mission add together text right after lastly occurrence of </section>.

looking @ these 2 seems if utilizing tac simpler don't understand how either: using sed append string 4th occurrence of pattern, http://www.unix.com/unix-dummies-questions-answers/46294-add-line-after-last-occurnace-pattern.html#post302149709

thanks.

it's easier add together things before first occurrence of string:

sed '/<\/preferences>/i\add text\nadd more text' file

results:

<?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 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 widget data" xml:space="preserve">{preferences}widgets/flag-button-1.5.4-1.oex</value> </section> add together text add together more text </preferences>

you can read more how insert line before string here. hth.

sed

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -