Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #60954
| From | Fritz Wuehler <fritz@spamexpire-202411.rodent.frell.theremailer.net> |
|---|---|
| Subject | Re: The joy of octal |
| References | <vgns2aqlhq@dont-email.me> <20241111090306.0000385d@gmail.com> <vgtr5s5ph3@dont-email.me> |
| Message-ID | <70ac3933f2b6e0f3539c739acc5a792d@msgid.frell.theremailer.net> (permalink) |
| Date | 2024-11-12 23:45 +0100 |
| Newsgroups | comp.os.linux.misc |
| Organization | dizum.com - The Internet Problem Provider |
Chris Ahlstrom <OFeem1...@teleworm.us> [CA]:
CA> I still haven't found a program that would easily reverse
CA> octal to a string.
You have to take into account the writer machine's endianness
and character set encoding (EBCDIC anyone?).
If it's a big-endian system and the encoding is ASCII, use the
following script. It preserves regular text and converts only what
it sees as octal numbers.
Modifying it to also accept EBCDIC encoded text on a non-EBCDIC
system is left as an exercise for the reader.
I would assume that if you could find a bourne shell, 'sed' and 'awk'
on some EBCDIC system, the script might work without changes.
Can anyone comment on this?
#!/bin/sh
DELIMITER="__octal_number_delimiter__" ;
# Step1: locate octal numbers in input
sed 's@\b\([0-7 ]\+\)\b@'"$DELIMITER"'\1'"$DELIMITER"'@g' |
# Step2: convert octal numbers to text, leaving everything else as it is
awk -v FS="$DELIMITER" -v Q='"' '{
for (i=1;i<=NF;i++) { # for all line fields
t = $i; # get the i-th line field
if (i%2) { # regular text; do not touch it
printf "%s", t;
} else { # octal number; process it
gsub(" ","", t); # remove any space characters first
# make sure the number of octal digits is a mulitiple of 6
for (j=1;j<=(length(t)%6);j++) t = "0" t;
# break up the octal string to sextuplets
for (j=1;j<=length(t)/6;j++) {
# convert a 6-digit octal number to a 4-digit hex number
six_octal_digits=substr(t,6*j-5,6);
four_hex_digits = sprintf ("%x", strtonum(0 six_octal_digits));
# process each pair of hex digits (a byte)
for (k=1;k<=length(four_hex_digits)/2;k++) {
two_hex_digits=substr(four_hex_digits,2*k-1, 2);
# output this byte as an ASCII character (escape non-printable ones)
char = strtonum("0x" two_hex_digits);
printf (((char < 32) ? "<%02x>" : "%c"), char);
}
}
}
}
print ""; # add a newline
}
'
Back to comp.os.linux.misc | Previous | Next — Previous in thread | Next in thread | Find similar
The joy of octal Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-11-09 09:36 -0500
Re: The joy of octal John Ames <commodorejohn@gmail.com> - 2024-11-11 09:03 -0800
Re: The joy of octal Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-11-11 15:58 -0500
Re: The joy of octal Louis Krupp <lkrupp@invalid.pssw.com.invalid> - 2024-11-12 02:30 -0700
Re: The joy of octal Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-11-12 07:29 -0500
Re: The joy of EBCDIC John Ames <commodorejohn@gmail.com> - 2024-11-12 11:14 -0800
Re: The joy of EBCDIC Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2024-11-12 19:51 +0000
Re: The joy of EBCDIC Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-11-12 16:12 -0500
Re: The joy of EBCDIC candycanearter07 <candycanearter07@candycanearter07.nomail.afraid> - 2024-11-12 22:20 +0000
Re: The joy of EBCDIC Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-11-13 06:59 -0500
Re: The joy of EBCDIC Fritz Wuehler <fritz@spamexpire-202411.rodent.frell.theremailer.net> - 2024-11-14 21:13 +0100
Re: The joy of EBCDIC Clemens Schüller <cs.usenet@mailbox.org> - 2024-11-14 21:20 +0100
Re: The joy of EBCDIC Eli the Bearded <*@eli.users.panix.com> - 2024-11-14 23:55 +0000
Re: The joy of pipes John Ames <commodorejohn@gmail.com> - 2024-11-14 16:09 -0800
Re: The joy of pipes Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-15 02:05 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-15 02:49 -0500
Re: The joy of pipes John Ames <commodorejohn@gmail.com> - 2024-11-15 07:55 -0800
Re: The joy of pipes Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-16 00:16 +0000
Re: The joy of pipes Robert Riches <spamtrap42@jacob21819.net> - 2024-11-16 04:33 +0000
Re: The joy of pipes Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-16 06:46 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-16 00:37 -0500
Re: The joy of pipes rbowman <bowman@montana.com> - 2024-11-16 06:16 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-16 03:03 -0500
Re: The joy of pipes Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2024-11-16 18:14 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-16 23:38 -0500
Re: The joy of pipes Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2024-11-16 18:14 +0000
Re: The joy of pipes Richard Kettlewell <invalid@invalid.invalid> - 2024-11-16 10:31 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-16 23:59 -0500
Re: The joy of pipes Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-17 05:30 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-17 01:05 -0500
Re: The joy of pipes Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-17 07:59 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-17 03:27 -0500
Re: The joy of pipes Richard Kettlewell <invalid@invalid.invalid> - 2024-11-17 08:42 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-17 22:50 -0500
Re: The joy of pipes Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-18 06:06 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-18 01:51 -0500
Re: The joy of pipes Pancho <Pancho.Jones@proton.me> - 2024-11-18 09:20 +0000
Re: The joy of pipes Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-18 09:36 +0000
Re: The joy of pipes Pancho <Pancho.Jones@proton.me> - 2024-11-18 11:05 +0000
Re: The joy of pipes The Natural Philosopher <tnp@invalid.invalid> - 2024-11-18 13:45 +0000
Re: The joy of pipes Pancho <Pancho.Jones@proton.me> - 2024-11-18 17:04 +0000
Re: The joy of pipes The Natural Philosopher <tnp@invalid.invalid> - 2024-11-18 17:47 +0000
Re: The joy of pipes rbowman <bowman@montana.com> - 2024-11-18 17:59 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-18 22:50 -0500
Re: The joy of pipes Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-19 04:53 +0000
Re: The joy of pipes The Natural Philosopher <tnp@invalid.invalid> - 2024-11-19 09:19 +0000
Re: The joy of pipes Richard Kettlewell <invalid@invalid.invalid> - 2024-11-19 09:56 +0000
Re: The joy of pipes rbowman <bowman@montana.com> - 2024-11-18 17:54 +0000
Re: The joy of pipes Pancho <Pancho.Jones@proton.me> - 2024-11-19 09:57 +0000
Re: The joy of pipes Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-19 21:55 +0000
Re: The joy of pipes "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-18 22:32 -0500
Re: The joy of pipes Robert Riches <spamtrap42@jacob21819.net> - 2024-11-19 04:50 +0000
Re: The joy of pipes Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-19 04:58 +0000
Re: The joy of pipes Eli the Bearded <*@eli.users.panix.com> - 2024-11-15 06:41 +0000
Re: The joy of EBCDIC Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2024-11-15 20:23 +0000
Re: The joy of octal Eli the Bearded <*@eli.users.panix.com> - 2024-11-12 20:09 +0000
Re: The joy of octal Fritz Wuehler <fritz@spamexpire-202411.rodent.frell.theremailer.net> - 2024-11-12 23:45 +0100
Re: The joy of octal "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-15 02:58 -0500
Re: The joy of octal rbowman <bowman@montana.com> - 2024-11-15 18:28 +0000
Re: The joy of octal Harold Stevens <wookie@aspen.localdomain> - 2024-11-15 14:30 -0600
Re: The joy of octal "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-16 00:01 -0500
Re: The joy of octal rbowman <bowman@montana.com> - 2024-11-16 05:50 +0000
Re: The joy of octal Andreas Eder <a_eder_muc@web.de> - 2024-11-16 15:14 +0100
Re: The joy of octal The Natural Philosopher <tnp@invalid.invalid> - 2024-11-16 14:38 +0000
Re: The joy of octal "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-17 00:57 -0500
Re: The joy of octal "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-15 23:31 -0500
Re: The joy of octal rbowman <bowman@montana.com> - 2024-11-16 05:24 +0000
Re: The joy of octal "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-16 03:20 -0500
Re: The joy of octal Don_from_AZ <djatechNOSPAM@comcast.net.invalid> - 2024-11-16 09:16 -0700
Re: The joy of octal "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-17 00:17 -0500
Re: The joy of octal rbowman <bowman@montana.com> - 2024-11-16 18:14 +0000
Re: The joy of octal "186282@ud0s4.net" <186283@ud0s4.net> - 2024-11-17 00:40 -0500
csiph-web