Groups | Search | Server Info | Login | Register


Groups > comp.lang.awk > #10063

Re: Can I output a binary file from an AWK program?

From Alan Mackenzie <acm@muc.de>
Newsgroups comp.lang.awk
Subject Re: Can I output a binary file from an AWK program?
Date 2026-03-29 11:30 +0000
Organization muc.de e.V.
Message-ID <10qb2gn$1knr$1@news.muc.de> (permalink)
References <10q99ai$ph7$1@news.muc.de> <10q9d0f$th8s$1@dont-email.me>

Show all headers | View raw


Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> On 2026-03-28 20:14, Alan Mackenzie wrote:
>> I think the Subject: line says it all.  I have a text source file to
>> convert into a binary output file.  For example, I want to be able to
>> output a 32-bit integer as a four byte little-endian binary integer.

> This needs clarification. - Note that Awk has no 32 bit integer data
> type. Usually you have text input, say "1234567", that is internally
> stored in a numerically interpreted field.

This field being either a string or a floating point number.  But I need
to output 32-bit integers regardless of the internal form.

>> Can AWK do this?  (It is supposed to by Turing complete, isn't it?)

> Of course that can be done. You could read in the number and apply a
> sequence of modulus and division operations on the read-in number; say
> awk '{n=$0; printf "%c\n", n%256; n=int(n/256); ... }'

OK, thanks.

> Or, in GNU Awk, you could extract the bytes by its bit-functions,
> and(), rshift(), to extract the octet parts, then print them as a
> character as above.

I see that now.  But it is ugly enough that maybe I really do want to
use some other language rather than AWK.

> Janis

-- 
Alan Mackenzie (Nuremberg, Germany).

Back to comp.lang.awk | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Can I output a binary file from an AWK program? Alan Mackenzie <acm@muc.de> - 2026-03-28 19:14 +0000
  Re: Can I output a binary file from an AWK program? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-03-28 21:17 +0100
    Re: Can I output a binary file from an AWK program? Alan Mackenzie <acm@muc.de> - 2026-03-29 11:30 +0000
      Re: Can I output a binary file from an AWK program? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-03-29 13:35 +0200
  Re: Can I output a binary file from an AWK program? Kaz Kylheku <046-301-5902@kylheku.com> - 2026-03-29 23:45 +0000
    Re: Can I output a binary file from an AWK program? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-29 17:07 -0700
      Re: Can I output a binary file from an AWK program? Kaz Kylheku <046-301-5902@kylheku.com> - 2026-04-17 00:25 +0000
  Re: Can I output a binary file from an AWK program? gazelle@shell.xmission.com (Kenny McCormack) - 2026-03-30 09:37 +0000
    Re: Can I output a binary file from an AWK program? gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-02 12:06 +0000

csiph-web