The simple one:
Inserting a line at the top of a file..
entropy ~ # echo "test file" > dump
entropy ~ # cat dump
test file
entropy ~ # sed -i '1iwoot_woot' dump
entropy ~ # cat dump
woot_woot
test file
The nifty one:
Making a sed replacement that isnt greedy..
assume a file contained the following line:
alert x blah blah blah blah; flagged: yes; set: yes; ignore: no;
alert y blah blah blah blah; flagged: yes; set: yes; ignore: no;
alert x blah blah blah blah; flagged: maybe; set: yes; ignore: no;
and you wanted to get rid of the flagged statement, whether it was set to "yes" or to "maybe" or to anything else, only on lines that start with alert x.
the following effectively gets rid of the "flagged" statement but the regex is greedy and also takes out the "set" statement:
entropy ~ # sed '\,^alert x,s/flagged:.*; //' blah
alert x blah blah blah blah; ignore: no;
alert y blah blah blah blah; flagged: yes; set: yes; ignore: no;
alert x blah blah blah blah; ignore: no;
alert x blah blah blah blah; ignore: no;
alert y blah blah blah blah; flagged: yes; set: yes; ignore: no;
alert x blah blah blah blah; ignore: no;
This one however limits its replacement based on the first encountered semicolon rather than the last, and thus does not greedily replace extra data:
alert x blah blah blah blah; set: yes; ignore: no;
alert y blah blah blah blah; flagged: yes; set: yes; ignore: no;
alert x blah blah blah blah; set: yes; ignore: no;