Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

File of bytes to binary file, but same data

37 views
Skip to first unread message

snosniv

unread,
Jun 24, 2016, 7:27:44 PM6/24/16
to
I have a file full of bytes, one byte per line, which I created with a Tcl script.
However, the bytes apparently need to be in a binary file format.

e.g file start looks like:

fd
37
65
d5
23
34
65
dc
ae
3a
4c
6a
12
6f
76
25

But if I open in binary, I get the ASCII of the bytes & all the CR/LF chard too.
I need to generate a binary file with the bytes above: e.g.

00000000 FD 37 65 d5.....etc

But if I open in binary I get:

00000000 66 64 0D 0A etc .

Tried various scan commands, but as only a Tcl dabbler, getting confused!

Any help most welcome.

Robert Heller

unread,
Jun 24, 2016, 8:34:44 PM6/24/16
to
Read these man pages:

man fconfigure
man binary

Briefly:

fconfigure $channel -buffering none -encoding binary -translation binary

puts $channel [binary format H2 FD]



>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

mse...@gmail.com

unread,
Jun 25, 2016, 3:42:29 AM6/25/16
to
Don't forget puts -nonewline [binary...]
binary files must always be -nonewlined

Martyn

Robert Heller

unread,
Jun 25, 2016, 7:49:37 AM6/25/16
to
Don't the fconfigure settings take care of that?

>
> Martyn

Peter Lewerin

unread,
Jun 25, 2016, 9:24:45 AM6/25/16
to

> Don't the fconfigure settings take care of that?

Nope. -translation binary prevents line endings from being translated to e.g. crlf, but neither -encoding binary nor -translation binary prevents puts from appending a line feed to the output.
0 new messages