bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: No ord() Hampers One-liners.


From: Aharon Robbins
Subject: Re: No ord() Hampers One-liners.
Date: Sun, 17 Jan 2010 22:07:14 +0200

Hi.

Please do some more reading in the gawk manual. There you will discover
(a) you can mix source files and command line programs with gawk, and
(b) that gawk supports an AWKPATH environment variable specifying where
it should search for files.

There is a fighting chance that on GNU/Linux systems you'll find
/usr/share/awk/ord.awk already installed. Thus you need merely use
something like

        export AWKPATH=.:/usr/share/awk
        gawk -f ord.awk --source '{ print ord($0) }'

and you'll be set.

You may also wish to investigate the igawk script, described in
the gawk doc and often installed in a standard place as well.

Hope this helps,

Arnold

> to: address@hidden
> subject: No ord() Hampers One-liners.
> Date: Sun, 17 Jan 2010 18:23:40 +0000
> From: Ralph Corderoy <address@hidden>
>
> Hi,
>
> I was needing an ord("A") -> 65 function.  I found
>
>     http://www.gnu.org/manual/gawk/html_node/Ordinal-Functions.html
>
> where justification is given for it not existing.  However, having to
> build a lookup table isn't particular useful when one's trying to
> concoct a shell one-liner.
>
>     awk 'BEGIN {for (i = 0; i < 256; i++) t[sprintf("%c", i)] = i}
>         {print t[substr($0, 1, 1)]}'
>
>     awk '{print ord($0)}'
>
> There's other things in awk that could be implemented in awk, e.g.
> index() with substr(), but we're given the benefit of those.  So this is
> just to ask for the issue to be reconsidered.  Although awk's being used
> for bigger tasks these days, some of us still like the little
> one-liners.  :-)
>
> Cheers,
> Ralph.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]