In GNU Awk I'm working with UTF-8 data and want to count _bytes_.
[...]
This one seems to works, but appears to be a bit clumsy...
$ awk '{print length (sprintf ("%s", $0)), ">" substr ($0, 2) "<" }'
aaa
3 >aa<
|n|n|n
3 >|n|n<
Is there any simpler (still native) way to keep string processing
logic to UTF-8 data intact but have the _byte count_ available?
Janis
So the original question remains:
Is there any simpler (still native) way to keep string processing
logic to UTF-8 data intact but have the _byte count_ available?
In article <116k77e$32eog$3@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
So the original question remains:
Is there any simpler (still native) way to keep string processing
logic to UTF-8 data intact but have the _byte count_ available?
The "mbs" extension in gawkextlib has an mbs_length() function
that will do the job:
------------------
@load "mbs"
{ print length($0), mbs_length($0) }
------------------
Try it out.
Otherwise, no, there is no way within gawk to get what you want.
On 2026-08-25 16:26, Mack The Knife wrote:
In article <116k77e$32eog$3@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
So the original question remains:
Is there any simpler (still native) way to keep string processing
logic to UTF-8 data intact but have the _byte count_ available?
The "mbs" extension in gawkextlib has an mbs_length() function
that will do the job:
------------------
@load "mbs"
{ print length($0), mbs_length($0) }
------------------
Try it out.
cannot open shared library `mbs' for reading: No such file or directory
Hmm.. - I'm getting an error (seems I need more information about that; >usually I don't use extensions!); I'll see how to fix my installation.
(Or maybe I'll just invoke a 'getline' on a Unix "wc -c" co-process.)
Otherwise, no, there is no way within gawk to get what you want.
Thanks for the confirmation!
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 74 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 121:15:21 |
| Calls: | 1,194 |
| Files: | 1,352 |
| Messages: | 290,208 |