Gentoo Archives: gentoo-user

From: meino.cramer@×××.de
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] OT: sed on the commandline
Date: Sat, 12 Feb 2011 13:12:29
Message-Id: 20110212131120.GJ7328@solfire
In Reply to: Re: [gentoo-user] OT: sed on the commandline by Alan McKinnon
1 Alan McKinnon <alan.mckinnon@×××××.com> [11-02-12 13:44]:
2 > Apparently, though unproven, at 13:25 on Saturday 12 February 2011,
3 > meino.cramer@×××.de did opine thusly:
4 >
5 > > Hi,
6 > >
7 > > I am trying to instruct sed to insert a line of text before
8 > > a matched line. The whole command should fit into one
9 > > physical (command) line.
10 > >
11 > > Is it possible? And how is it possible?
12 > >
13 > > Thank you very much for any hint in advance!
14 > > Best regards,
15 > > mcc
16 >
17 >
18 > There's nothing special about a line, it's just a bunch of characters that end
19 > with a newline (itself just a character).
20 >
21 > But you can't insert stuff at arbitrary points, you can only replace stuff
22 > with other stuff. You can replace the start of line marker (^), so do this:
23 >
24 > $ cat sed.txt
25 > 1
26 > 2
27 > $ cat sed.txt | sed -e 's/^/a\n/g'
28 > a
29 > 1
30 > a
31 > 2
32 >
33 > I replaced "start of line" with "a and a newline". Modify the regex to suit
34 > your needs. This gets awkward though, as you can search with a regex but only
35 > replace a literal. If you need to insert some line before any line containing
36 > say a "z" for example, then that is way beyond sed's capabilities and you are
37 > into awk|perl territory.
38 >
39 > You didn't clearly state what you are trying to do with examples, so the above
40 > vague wishy-washy goop is the best I can do for you.
41 >
42 >
43 > --
44 > alan dot mckinnon at gmail dot com
45 >
46
47 Hi,
48
49 I update my MakeHuman svn source and the Blender svn source on a daily
50 basis. Currently the Blender folks did a change in the registration
51 code for Blender scripts. The MakeHuman folks provide a script, which
52 is needed to load the putput of MakeHuman into Blender. This script
53 isn't "new registration ready".
54
55 I have to do the following the changes to the Makehuman script (a
56 handfull):
57
58 change this: =======================================
59 def registration()
60 <script specific stuff
61
62
63 def unregistration()
64 <script specific stuff
65
66 into this: =========================================
67 def registration()
68 bpy.utils.register_module(__name__)
69 <script specific stuff
70
71
72 def unregistration()
73 bpy.utils.unregister_module(__name__)
74 <script specific stuff
75
76
77 until the MakeHuman folks have time to integrate my patch into their
78 code.
79
80 Since I do update often I would have to edit all these files by hand
81 every time.
82
83 It would be much more time saveing, if a sed-oneliner from the
84 commandline, saved into the shell history, could do this for me....
85
86 I googled a little in beforehand and found the "a" command, but I
87 didn't managed to get it working for me...so...
88
89 Best regards,
90 mcc

Replies

Subject Author
Re: [gentoo-user] OT: sed on the commandline Etaoin Shrdlu <shrdlu@×××××××××××××.org>