Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail 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: Sun, 29 Mar 2026 23:45:18 -0000 (UTC) Organization: A noiseless patient Spider Lines: 29 Message-ID: <20260329163603.959@kylheku.com> References: <10q99ai$ph7$1@news.muc.de> Injection-Date: Sun, 29 Mar 2026 23:45:19 +0000 (UTC) Injection-Info: dont-email.me; posting-host="b5ba0d3616de7f4f6660765713518f1a"; logging-data="2115445"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tbQ5l9Owfi5U/m/D5wg4qfHtrrRoP0po=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:fcY4jjgzmBOHRki/7mcIuDYCyzs= Xref: csiph.com comp.lang.awk:10065 On 2026-03-28, 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. 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