[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
No ord() Hampers One-liners.
From: |
Ralph Corderoy |
Subject: |
No ord() Hampers One-liners. |
Date: |
Sun, 17 Jan 2010 18:23:40 +0000 |
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.
- No ord() Hampers One-liners.,
Ralph Corderoy <=