On Sat, 12 Feb 2011 14:11:20 +0100 meino.cra...@gmx.de wrote: > Alan McKinnon <alan.mckin...@gmail.com> [11-02-12 13:44]: > > Apparently, though unproven, at 13:25 on Saturday 12 February 2011, > > meino.cra...@gmx.de did opine thusly: > > > > > Hi, > > > > > > I am trying to instruct sed to insert a line of text before > > > a matched line. The whole command should fit into one > > > physical (command) line. > > > > > > Is it possible? And how is it possible? > > > > > > Thank you very much for any hint in advance! > > > Best regards, > > > mcc > > > > > > There's nothing special about a line, it's just a bunch of characters > > that end with a newline (itself just a character). > > > > But you can't insert stuff at arbitrary points, you can only replace > > stuff with other stuff. You can replace the start of line marker (^), > > so do this: > > > > $ cat sed.txt > > 1 > > 2 > > $ cat sed.txt | sed -e 's/^/a\n/g' > > a > > 1 > > a > > 2 > > > > I replaced "start of line" with "a and a newline". Modify the regex to > > suit your needs. This gets awkward though, as you can search with a > > regex but only replace a literal. If you need to insert some line > > before any line containing say a "z" for example, then that is way > > beyond sed's capabilities and you are into awk|perl territory. > > > > You didn't clearly state what you are trying to do with examples, so > > the above vague wishy-washy goop is the best I can do for you. > > > > > > -- > > alan dot mckinnon at gmail dot com > > > > Hi, > > I update my MakeHuman svn source and the Blender svn source on a daily > basis. Currently the Blender folks did a change in the registration > code for Blender scripts. The MakeHuman folks provide a script, which > is needed to load the putput of MakeHuman into Blender. This script > isn't "new registration ready". > > I have to do the following the changes to the Makehuman script (a > handfull): > > change this: ======================================= > def registration() > <script specific stuff > > > def unregistration() > <script specific stuff > > into this: ========================================= > def registration() > bpy.utils.register_module(__name__) > <script specific stuff > > > def unregistration() > bpy.utils.unregister_module(__name__) > <script specific stuff >
So it looks like you have to add a line *after* a match, not before as you originally said. Try this then: sed '/matchingline/s/$/\ninsertedline/' which in your case will likely be something like sed '/def registration()/s/$/\nbpy.utils.register_module(__name__)/' you can do both insertions in a single sed script, eg sed '/def registration()/s/$/\nbpy.utils.register_module(__name__)/ /def unregistration()/s/$/\nbpy.utils.unregister_module(__name__)/'