Re: [gentoo-user] OT: sed on the commandline

2011-02-12 Thread meino . cramer
Etaoin Shrdlu  [11-02-12 14:36]:
> On Sat, 12 Feb 2011 14:11:20 +0100
> meino.cra...@gmx.de wrote:
> 
> > Alan McKinnon  [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()
> > 

Re: [gentoo-user] OT: sed on the commandline

2011-02-12 Thread Etaoin Shrdlu
On Sat, 12 Feb 2011 14:11:20 +0100
meino.cra...@gmx.de wrote:

> Alan McKinnon  [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()
> 

Re: [gentoo-user] OT: sed on the commandline

2011-02-12 Thread meino . cramer
Alan McKinnon  [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()

Re: [gentoo-user] OT: sed on the commandline

2011-02-12 Thread Etaoin Shrdlu
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

2011-02-12 Thread dhk
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

2011-02-12 Thread Alan McKinnon
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