9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] how to output NUL byte from awk?
@ 2013-09-17 13:47 dexen deVries
  2013-09-17 14:03 ` Kurt H Maier
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: dexen deVries @ 2013-09-17 13:47 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

awk(1) says, ``[s]tring constants are quoted " ", with the usual C escapes 
recognized within.'', but \0 seems to terminate internal string 
reprezentation...

so how do i output a real NUL byte?



-- 
dexen deVries

[[[↓][→]]]




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] how to output NUL byte from awk?
  2013-09-17 13:47 [9fans] how to output NUL byte from awk? dexen deVries
@ 2013-09-17 14:03 ` Kurt H Maier
  2013-09-17 14:36   ` dexen deVries
  2013-09-17 16:50   ` erik quanstrom
  2013-09-17 17:50 ` arnold
  2013-09-18  7:24 ` Florian Limberger
  2 siblings, 2 replies; 11+ messages in thread
From: Kurt H Maier @ 2013-09-17 14:03 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Quoting dexen deVries <dexen.devries@gmail.com>:

> awk(1) says, ``[s]tring constants are quoted " ", with the usual C escapes
> recognized within.'', but \0 seems to terminate internal string
> reprezentation...
>
> so how do i output a real NUL byte?
>

Does printf not do this?

khm




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] how to output NUL byte from awk?
  2013-09-17 14:03 ` Kurt H Maier
@ 2013-09-17 14:36   ` dexen deVries
  2013-09-17 16:50   ` erik quanstrom
  1 sibling, 0 replies; 11+ messages in thread
From: dexen deVries @ 2013-09-17 14:36 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Tuesday 17 of September 2013 14:03:11 Kurt H Maier wrote:
> Quoting dexen deVries <dexen.devries@gmail.com>:
> > awk(1) says, ``[s]tring constants are quoted " ", with the usual C escapes
> > recognized within.'', but \0 seems to terminate internal string
> > reprezentation...
> >
> > so how do i output a real NUL byte?
>
> Does printf not do this?


thanks
i feel really dumb now ;-)


--
dx



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] how to output NUL byte from awk?
  2013-09-17 14:03 ` Kurt H Maier
  2013-09-17 14:36   ` dexen deVries
@ 2013-09-17 16:50   ` erik quanstrom
  2013-09-17 17:12     ` dexen deVries
                       ` (2 more replies)
  1 sibling, 3 replies; 11+ messages in thread
From: erik quanstrom @ 2013-09-17 16:50 UTC (permalink / raw)
  To: 9fans

On Tue Sep 17 10:04:20 EDT 2013, khm@sciops.net wrote:
> Quoting dexen deVries <dexen.devries@gmail.com>:
>
> > awk(1) says, ``[s]tring constants are quoted " ", with the usual C escapes
> > recognized within.'', but \0 seems to terminate internal string
> > reprezentation...
> >
> > so how do i output a real NUL byte?
> >
>
> Does printf not do this?

no, awk's printf does not do that:
minooka;  awk 'BEGIN{printf "%c", utf(0)}' | wc
      0       0       0
minooka; awk 'BEGIN{printf "%.5s", "12\034567890"}' | xd -1
0000000  31 32 1c 35 36
minooka; awk 'BEGIN{printf "%.5s", "12\0\034567890"}' | xd -1
0000000  31 32

- erik



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] how to output NUL byte from awk?
  2013-09-17 16:50   ` erik quanstrom
@ 2013-09-17 17:12     ` dexen deVries
  2013-09-17 18:55     ` dexen deVries
  2013-09-17 19:07     ` Kurt H Maier
  2 siblings, 0 replies; 11+ messages in thread
From: dexen deVries @ 2013-09-17 17:12 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Tuesday 17 of September 2013 12:50:07 erik quanstrom wrote:
> On Tue Sep 17 10:04:20 EDT 2013, khm@sciops.net wrote:
> > Quoting dexen deVries <dexen.devries@gmail.com>:
> > > awk(1) says, ``[s]tring constants are quoted " ", with the usual C
> > > escapes
> > > recognized within.'', but \0 seems to terminate internal string
> > > reprezentation...
> > > 
> > > so how do i output a real NUL byte?
> > 
> > Does printf not do this?
> 
> no, awk's printf does not do that:
> minooka;  awk 'BEGIN{printf "%c", utf(0)}' | wc
>       0       0       0
> minooka; awk 'BEGIN{printf "%.5s", "12\034567890"}' | xd -1
> 0000000  31 32 1c 35 36
> minooka; awk 'BEGIN{printf "%.5s", "12\0\034567890"}' | xd -1
> 0000000  31 32


printf "%c", 0


-- 
dexen deVries

[[[↓][→]]]

Take care of the luxuries and the necessities will take care of themselves.
                -- L. Long




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] how to output NUL byte from awk?
  2013-09-17 13:47 [9fans] how to output NUL byte from awk? dexen deVries
  2013-09-17 14:03 ` Kurt H Maier
@ 2013-09-17 17:50 ` arnold
  2013-09-18  7:24 ` Florian Limberger
  2 siblings, 0 replies; 11+ messages in thread
From: arnold @ 2013-09-17 17:50 UTC (permalink / raw)
  To: 9fans

dexen deVries <dexen.devries@gmail.com> wrote:

> awk(1) says, ``[s]tring constants are quoted " ", with the usual C escapes
> recognized within.'', but \0 seems to terminate internal string
> reprezentation...
>
> so how do i output a real NUL byte?

Tooting my own horn (sorry)

	gawk 'BEGIN { printf("\0") }'

"No arbitrary limits" in action. :-)

Arnold



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] how to output NUL byte from awk?
  2013-09-17 16:50   ` erik quanstrom
  2013-09-17 17:12     ` dexen deVries
@ 2013-09-17 18:55     ` dexen deVries
  2013-09-17 19:07     ` Kurt H Maier
  2 siblings, 0 replies; 11+ messages in thread
From: dexen deVries @ 2013-09-17 18:55 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Tuesday 17 of September 2013 12:50:07 erik quanstrom wrote:
> On Tue Sep 17 10:04:20 EDT 2013, khm@sciops.net wrote:
> > Quoting dexen deVries <dexen.devries@gmail.com>:
> > > awk(1) says, ``[s]tring constants are quoted " ", with the usual C
> > > escapes
> > > recognized within.'', but \0 seems to terminate internal string
> > > reprezentation...
> > >
> > > so how do i output a real NUL byte?
> >
> > Does printf not do this?
>
> no, awk's printf does not do that:
> minooka;  awk 'BEGIN{printf "%c", utf(0)}' | wc
>       0       0       0
> minooka; awk 'BEGIN{printf "%.5s", "12\034567890"}' | xd -1
> 0000000  31 32 1c 35 36
> minooka; awk 'BEGIN{printf "%.5s", "12\0\034567890"}' | xd -1
> 0000000  31 32



utf() is the problem, %c expect int, not string:

9 awk ' BEGIN { printf "%c", 0 } ' | 9 wc
      0       1       1


9 awk ' BEGIN { printf "X%cX", 0 } ' | 9 xd
0000000  58005800


--
dx



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] how to output NUL byte from awk?
  2013-09-17 16:50   ` erik quanstrom
  2013-09-17 17:12     ` dexen deVries
  2013-09-17 18:55     ` dexen deVries
@ 2013-09-17 19:07     ` Kurt H Maier
  2013-09-17 19:21       ` cinap_lenrek
  2 siblings, 1 reply; 11+ messages in thread
From: Kurt H Maier @ 2013-09-17 19:07 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Quoting erik quanstrom <quanstro@quanstro.net>:

> On Tue Sep 17 10:04:20 EDT 2013, khm@sciops.net wrote:
>
> no, awk's printf does not do that:
> minooka;  awk 'BEGIN{printf "%c", utf(0)}' | wc

not if you ask it to convert '0' to unicode and then covert
the unicode value to a char, no.   I'm almost positive if you
tell it to cast 0 (the number) to char and print it, it will
give you a null byte.

khm





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] how to output NUL byte from awk?
  2013-09-17 19:07     ` Kurt H Maier
@ 2013-09-17 19:21       ` cinap_lenrek
  0 siblings, 0 replies; 11+ messages in thread
From: cinap_lenrek @ 2013-09-17 19:21 UTC (permalink / raw)
  To: 9fans

confirmed.

--
cinap



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] how to output NUL byte from awk?
  2013-09-17 13:47 [9fans] how to output NUL byte from awk? dexen deVries
  2013-09-17 14:03 ` Kurt H Maier
  2013-09-17 17:50 ` arnold
@ 2013-09-18  7:24 ` Florian Limberger
  2013-09-18  7:36   ` Bruce Ellis
  2 siblings, 1 reply; 11+ messages in thread
From: Florian Limberger @ 2013-09-18  7:24 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 468 bytes --]

On Tue, 17 Sep 2013 15:47:17 +0200
dexen deVries <dexen.devries@gmail.com> wrote:

> awk(1) says, ``[s]tring constants are quoted " ", with the usual C
> escapes recognized within.'', but \0 seems to terminate internal
> string reprezentation...
> 
> so how do i output a real NUL byte?

I  know this is not very constructive and may seem like a dumb question,
but isn’t \0 the end marker for C strings?  So this behaviour  might  be
expected?


-flo

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 853 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] how to output NUL byte from awk?
  2013-09-18  7:24 ` Florian Limberger
@ 2013-09-18  7:36   ` Bruce Ellis
  0 siblings, 0 replies; 11+ messages in thread
From: Bruce Ellis @ 2013-09-18  7:36 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 649 bytes --]

spot on. that's why:

printf "%c", 0

works, move on now.


On 18 September 2013 17:24, Florian Limberger
<flo@snakeoilproductions.net>wrote:

> On Tue, 17 Sep 2013 15:47:17 +0200
> dexen deVries <dexen.devries@gmail.com> wrote:
>
> > awk(1) says, ``[s]tring constants are quoted " ", with the usual C
> > escapes recognized within.'', but \0 seems to terminate internal
> > string reprezentation...
> >
> > so how do i output a real NUL byte?
>
> I  know this is not very constructive and may seem like a dumb question,
> but isn’t \0 the end marker for C strings?  So this behaviour  might  be
> expected?
>
>
> -flo
>

[-- Attachment #2: Type: text/html, Size: 1587 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-09-18  7:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-17 13:47 [9fans] how to output NUL byte from awk? dexen deVries
2013-09-17 14:03 ` Kurt H Maier
2013-09-17 14:36   ` dexen deVries
2013-09-17 16:50   ` erik quanstrom
2013-09-17 17:12     ` dexen deVries
2013-09-17 18:55     ` dexen deVries
2013-09-17 19:07     ` Kurt H Maier
2013-09-17 19:21       ` cinap_lenrek
2013-09-17 17:50 ` arnold
2013-09-18  7:24 ` Florian Limberger
2013-09-18  7:36   ` Bruce Ellis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).