Re: [gentoo-user] OT: sed on the commandline
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
Re: [gentoo-user] OT: sed on the commandline
On 02/12/2011 06:25 AM, meino.cra...@gmx.de wrote: 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 Try the ampersand like the example below. Make a file of phone numbers. $ cat phone.txt 555-1212 555-1234 555- Then run the following command to prefix the number with 212 and a dash. $ sed 's/555/212-/' phone.txt 212-555-1212 212-555-1234 212-555- Try moving the ampersand around the replacement string. If moved to the beginning it transposes the numbers. Note: The dash was moved to make the result look better, it has nothing to do with the command. $ sed 's/555/-212/' phone.txt 555-212-1212 555-212-1234 555-212-
Re: [gentoo-user] OT: sed on the commandline
On Sat, 12 Feb 2011 12:25:20 +0100 meino.cra...@gmx.de wrote: 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? sed 's/matchingline/insertedline\n/'
Re: [gentoo-user] OT: sed on the commandline
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 until the MakeHuman folks have time to integrate my patch into their code. Since I do update often I would have to edit all these files by hand every time. It would be much more time saveing, if a sed-oneliner from the commandline, saved into the shell history, could do this for me I googled a little in beforehand and found the a command, but I didn't managed to get it working for me...so... Best regards, mcc
Re: [gentoo-user] OT: sed on the commandline
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__)/'
Re: [gentoo-user] OT: sed on the commandline
Etaoin Shrdlu shr...@unlimitedmail.org [11-02-12 14:36]: 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__)/' Hi, thank you for this hint! :) My first posting was made at a time as I thought only one script has this issue. For this one script I had matched another line inside of register(). But all scripts of MakeHuman are affected...so... :) Anyway...your solution works as a charme and therefor the scripts are registered with blender again :) Have a nice weekend! Best regards, mcc