Groups | Search | Server Info | Login | Register
Groups > comp.lang.awk > #10065
| From | Kaz Kylheku <046-301-5902@kylheku.com> |
|---|---|
| Newsgroups | comp.lang.awk |
| Subject | Re: Can I output a binary file from an AWK program? |
| Date | 2026-03-29 23:45 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <20260329163603.959@kylheku.com> (permalink) |
| References | <10q99ai$ph7$1@news.muc.de> |
On 2026-03-28, Alan Mackenzie <acm@muc.de> 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.
Firstly, Awk's printf has a %c specifier which will output any byte:
$ awk 'BEGIN { printf("%c%c", 0x41, 0x0A) }'
A
$
Another idea is to output a textual dump compatible with xxd.
(xxd == fairly widely installed utility that comes with Vim).
xxd can revert xxd dumps back to binary:
$ xxd /etc/bash_completion
00000000: 2e20 2f75 7372 2f73 6861 7265 2f62 6173 . /usr/share/bas
00000010: 682d 636f 6d70 6c65 7469 6f6e 2f62 6173 h-completion/bas
00000020: 685f 636f 6d70 6c65 7469 6f6e 0a h_completion.
$ xxd /etc/bash_completion | xxd -r
. /usr/share/bash-completion/bash_completion
IIRC there is a bit of tolerance in "xxd -r". Indeed:
$ xxd -r
0: 41 57 4B 0A
AWK
0: 42 494E 0A
BIN
Back to comp.lang.awk | Previous | Next — Previous in thread | Next in thread | Find similar
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