procmail
[Top] [All Lists]

Re: A tip (was: Reversing text?)

2002-05-15 03:01:15
On Wed, 15 May 2002 erik(_at_)dd(_dot_)nec(_dot_)com(_dot_)au wrote:

On Tue, May 14, 2002 at 01:29:18PM +0300, Udi Mottelo wrote:

awk 'BEGIN{NF=split(O,T,".");for(i=NF;i;i--)N=N"/"T[i];print N;exit}' 
O=$MATCH

Udi,

   That's nifty!

        Believe me, i have good meanings (:-)

   One hint, though. As is, the script depends on which awk are you using.
Standard awks should not recognise command-line variable assignments in the
BEGIN action. Gawk does, but only if the assignment is prefixed with -v.

        Sorry, I test it on SGI (IRIX64 6.5 6.5.14m) by awk(1) and nawk(1).
        The awk is _SUPPOSED_TO_BE_ compatible with standard awk, and the
        nawk is supposed to be compatible with gawk.
        However, here is the good version (?)

awk 'BEGIN{NF=split("'$MATCH'",T,".");for(i=NF;i;i--)N=N"/"T[i];print N;exit}'

        This version was tested on: Solari7 (awk, nawk), SGI ((awk, nawk),
        RedHet7.1 (awk, gawk), OSF1 P4.0 (awk, nawk).  Sorry, I have no more
        machines to check. (we have IRIX (IBM) but i have no passwd..)

Bye,
 Udi


man gawk >>>
       -v var=val
       --assign var=val
         Assign  the  value  val to the variable var, before execution of the
         program   begins.   Such variable values  are  available to the BEGIN
         block of an AWK program.

   ...

POSIX COMPATIBILITY

   ...

       The book indicates that command line  variable  assignment
       happens when  awk  would otherwise open the argument as a
       file, which is after the BEGIN block  is  executed.   How-
       ever,  in earlier implementations, when such an assignment
       appeared before any file names, the assignment would  hap-
       pen  before the BEGIN block was run.  Applications came to
       depend on this "feature."  When awk was changed   to  match
       its  documentation,  the -v option for assigning variables
       before program execution was added to accommodate applica-
       tions  that depended upon the old behavior.  (This feature
       was agreed upon by both the Bell Laboratories and the  GNU
       developers.)
<<<

Regards,
Erik

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail


--

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>