On 24.06.11 18:37, Mark wrote:
> On Fri, Jun 24, 2011 at 3:59 AM, Erik Christiansen
> <dva...@internode.on.net>wrote:
> 
> [...]
> 
> 
> > $ echo G1 X53.6223 Y37.9513 Eggnog F2300 | sed -re 's/( E)([0-9]+)/ A\2/'
> > G1 X53.6223 Y37.9513 Eggnog F2300
> >
> 
> There is still a potential problem: comments will be modified if they
> contain ' Ennn'.

But is that a problem? The filter is invoked in a pipeline, only to feed
the EMC2 parser, in the current use case, AIUI. So comments are unseen,
and stripped by EMC2.

> $ echo "G1 X53.6223 Y37.9513 Eggnog F2300 (MSG, Move to point E1 )" | sed
> -re 's/( E)([0-9]+)/ A\2/'
> G1 X53.6223 Y37.9513 Eggnog F2300 (MSG, Move to point A1 )

[...]

> I'm not nearly enough of a sed guru to tell you how to make it ignore
> matches within parenthesis.

The additional power of the next tool up makes reasonably light work of
the context conditionality. The short gnu awk script "eaxis" below skips
Eggnog, changes E2300, and skips the comment, leaving "E1":

$ echo "G1 X53.6223 Y37.9513 Eggnog E2300 (MSG, Move to point E1 )" | eaxis
G1 X53.6223 Y37.9513 Eggnog A2300 (MSG, Move to point E1 )

I've attached the example script, which is written for lack of
obscurity rather than brevity. The current use case is satisfied
without the IGNORECASE line, so it may be omitted. (It is only there
because it could become useful if we want to be more general.)

The way that we "Only do lines which need it." is to match E[0-9]+
only if it is not preceded by a comment delimiter. To do that, the
[^\(] is a negated character class, containing every character except
'(', anchored to the start of the line by the preceding '^'. (The
enclosed '^' negates the class. The '\' escapes the '(' metacharacter,
to make it a literal character.) Gawk uses EREs by default, so no
command options are needed for that. 

Another benefit of moving up one tool level is that any add-on filtering
features are easier to implement.

Erik

-- 
"Microsoft is not the answer. It is the question. The answer is 'No'."
                                                           - Unknown


#!/bin/bash

# Change E axis to A axis, but leave comments untouched.

gawk '
BEGIN { IGNORECASE = 1 }                     # Mimic insensitivity of EMC2.

/^[^\(]* E[0-9]+/ {                          # Only do lines which need it.
   for (i=1; i<=NF; i++)                     # Do all fields in the line,
   {  if ($i ~ /\(/) break                   # but only up to the comment.
      if ($i ~ /^E[0-9]+/) sub("E","A",$i)
   }
}

   { print }                                 # Print everything.

' $*
------------------------------------------------------------------------------
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