Erik,
thanks for the correction, you might indeed be a guru!
/Lars

> -----Original Message-----
> From: Erik Christiansen [mailto:dva...@internode.on.net]
> Sent: den 24 juni 2011 10:00
> To: emc-users@lists.sourceforge.net
> Subject: Re: [Emc-users] Axis naming X Y Z E, can I have that?
> 
> On 23.06.11 22:19, Lars Andersson wrote:
> > Nice to have the file conversion integrated in AXIS.
> > No need to change the axis name then.
> 
> Thank you for the nicely potted integration example.
> I'll certainly keep it for reference.
> 
> [...]
> 
> > This is E2A that was run from outside of AXIS before
> >     #!/bin/bash
> >     sed -e 's/\( E\)\([0-9]*\)/ A\2/' $1
> > Guru comments on this?
> 
> Now that's asking for opinion as well as help. ;-)
> 
> Here's 1.5c worth of one or the other: The above regex is in BRE (Basic
> Regular Expression) form, and so is partly obscured by a flurry of
> backslashes.
> Readability is improved (innit?) if we allow sed to use ERE (Extended
> Regular
> Expressions), like this:
> 
> sed -re 's/( E)([0-9]*)/ A\2/' $1
> 
> Now it's human readable, yet has identical behaviour:
> 
> echo G1 X53.6223 Y37.9513 E49.6224 F2300 | sed -re 's/( E)([0-9]*)/
> A\2/'
> G1 X53.6223 Y37.9513 A49.6224 F2300
> 
> Now it's also easier to see that the regex may have a weakness, in that
> [0-9]* matches "zero or more digits". That means it is no more
> selective
> than:
> 
> sed -re 's/ E/ A/'
> 
> As we see here:
> 
> $ echo G1 X53.6223 Y37.9513 Eggnog F2300 | sed -re 's/( E)([0-9]*)/
> A\2/'
> G1 X53.6223 Y37.9513 Aggnog F2300
> 
> $ echo G1 X53.6223 Y37.9513 Eggnog 49.6224 F2300 | sed -re 's/ E/ A/'
> G1 X53.6223 Y37.9513 Aggnog 49.6224 F2300
> 
> To make the second regex atom do anything, we need to ask for "one or
> more", like so:
> 
> $ echo G1 X53.6223 Y37.9513 E49.6224 F2300 | sed -re 's/( E)([0-9]+)/
> A\2/'
> G1 X53.6223 Y37.9513 A49.6224 F2300
> 
> $ echo G1 X53.6223 Y37.9513 Eggnog F2300 | sed -re 's/( E)([0-9]+)/
> A\2/'
> G1 X53.6223 Y37.9513 Eggnog F2300
> 
> Now it only acts in the desired context. (Hopefully I haven't
> belaboured
> the explanation too much, in trying to be explicit.)
> 
> Since sed, awk, grep, etc all understand ERE as well as BRE, I've never
> found a downside to using the more readable form. Less typing too.
> (Even vim can be weaned off its tedious backslash addiction by
> prepending \v to the regex expression.)
> 
> There's also this advice in "man 7 regex":
> 
> »
> Regular expressions ("RE"s), as defined in POSIX.2, come in two forms:
> modern REs (roughly those of egrep; POSIX.2 calls these "extended" REs)
> and obsolete  REs  (roughly  those  of ed(1); POSIX.2 "basic" REs).
> Obsolete REs mostly exist for backward compatibility in some old
> programs; they will be discussed at the end.
> «
> 
> Whew! I'm glad we get to keep the good ones.
> 
> Erik
> 
> --
> The wonderful thing about standards is that there are so many of them.
>                                                         - Andy
> Tanenbaum
> 
> 
> -----------------------------------------------------------------------
> -------
> All the data continuously generated in your IT infrastructure contains
> a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense..
> http://p.sf.net/sfu/splunk-d2d-c1
> _______________________________________________
> Emc-users mailing list
> Emc-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/emc-users


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a 
definitive record of customers, application performance, security 
threats, fraudulent activity and more. Splunk takes this data and makes 
sense of it. Business sense. IT sense. Common sense.. 
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to