* A little UNIX scripting challenge...
@ 2004-05-27 15:23 nikki_wire
2004-05-28 5:22 ` TyBreaker
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: nikki_wire @ 2004-05-27 15:23 UTC (permalink / raw)
Hello!
I am a UNIX novice but I'd like to write a script to decode some
output - I was wondering if anyone could help me out with it?
Here's what I'd like to do.
I have some HEX output. eg. 81 ea 70 90 cd 05 8b 95 40 00
I'd like to convert that to strict 8 bit binary with a zero as the
filler for the extra characters but starting from the last 2 digits
and working backwards.
So for the above it would become 00 40 95 8b 05 cd 90 70 ea 81 and
then subsequently 00000000 01000000 10010101 10001011 00000101
11001101 10010000 01110000 11101010 10000001 (I think that's right!)
Does anyone have a way to do this? If so I'd appreciate it!
Thanks
Nikki
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: A little UNIX scripting challenge...
2004-05-27 15:23 A little UNIX scripting challenge nikki_wire
@ 2004-05-28 5:22 ` TyBreaker
2004-05-28 11:26 ` nikki_wire
2004-05-28 16:12 ` nikki_wire
2 siblings, 0 replies; 9+ messages in thread
From: TyBreaker @ 2004-05-28 5:22 UTC (permalink / raw)
Here's a script that'll do it:
#!/bin/sh
echo "81 ea 70 90 cd 05 8b 95 40 00" | awk '{
print "obase=2"
print "ibase=16"
for (i=NF; i > 0; i--) print toupper($i)
}' | bc | awk '{ printf "%.8d ", $1 }'
Any enhancements will be an exercise for the reader!
"nikki_wire" <nikki_wire@yahoo.com> wrote in message
news:60fdd9c9.0405270723.33f51cc3@posting.google.com...
> Hello!
>
> I am a UNIX novice but I'd like to write a script to decode some
> output - I was wondering if anyone could help me out with it?
>
> Here's what I'd like to do.
>
> I have some HEX output. eg. 81 ea 70 90 cd 05 8b 95 40 00
>
> I'd like to convert that to strict 8 bit binary with a zero as the
> filler for the extra characters but starting from the last 2 digits
> and working backwards.
> So for the above it would become 00 40 95 8b 05 cd 90 70 ea 81 and
> then subsequently 00000000 01000000 10010101 10001011 00000101
> 11001101 10010000 01110000 11101010 10000001 (I think that's right!)
>
> Does anyone have a way to do this? If so I'd appreciate it!
>
> Thanks
>
> Nikki
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: A little UNIX scripting challenge...
2004-05-27 15:23 A little UNIX scripting challenge nikki_wire
2004-05-28 5:22 ` TyBreaker
@ 2004-05-28 11:26 ` nikki_wire
2004-05-28 21:48 ` TyBreaker
2004-05-28 16:12 ` nikki_wire
2 siblings, 1 reply; 9+ messages in thread
From: nikki_wire @ 2004-05-28 11:26 UTC (permalink / raw)
Thanks very much indeed for this - that is brilliant.
I wonder if I could push my luck and ask if you or anyone is able to
extend this script to decode the data a little further.
With the output you generated with your script, I'd like to remove all
the spaces and split the data into 7 bit chunks starting from the end.
These 7 bit chunks would then be decoded back to hex. So for our
example: 00000000 01000000 10010101 10001011 00000101 11001101
10010000 01110000 11101010 10000001 becomes:
1000000 => 40
1010101 => 55
1100001 => 61
Well, that's the first 3 anyway but you get the idea...
I am sorry I am not able to work this out for myself - as I said I am
a UNIX novice.
Thanks very much!
Nikki
nikki_wire@yahoo.com (nikki_wire) wrote in message news:<60fdd9c9.0405270723.33f51cc3@posting.google.com>...
> Hello!
>
> I am a UNIX novice but I'd like to write a script to decode some
> output - I was wondering if anyone could help me out with it?
>
> Here's what I'd like to do.
>
> I have some HEX output. eg. 81 ea 70 90 cd 05 8b 95 40 00
>
> I'd like to convert that to strict 8 bit binary with a zero as the
> filler for the extra characters but starting from the last 2 digits
> and working backwards.
> So for the above it would become 00 40 95 8b 05 cd 90 70 ea 81 and
> then subsequently 00000000 01000000 10010101 10001011 00000101
> 11001101 10010000 01110000 11101010 10000001 (I think that's right!)
>
> Does anyone have a way to do this? If so I'd appreciate it!
>
> Thanks
>
> Nikki
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little UNIX scripting challenge...
2004-05-28 11:26 ` nikki_wire
@ 2004-05-28 21:48 ` TyBreaker
2004-05-28 21:56 ` TyBreaker
0 siblings, 1 reply; 9+ messages in thread
From: TyBreaker @ 2004-05-28 21:48 UTC (permalink / raw)
nikki_wire wrote:
> With the output you generated with your script, I'd like to remove all
> the spaces and split the data into 7 bit chunks starting from the end.
> These 7 bit chunks would then be decoded back to hex. So for our
> example: 00000000 01000000 10010101 10001011 00000101 11001101
> 10010000 01110000 11101010 10000001 becomes:
>
> 1000000 => 40
> 1010101 => 55
> 1100001 => 61
Sorry, lost you here, don't understand from what you said how you
arrived at these 7-bit sequences.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little UNIX scripting challenge...
2004-05-28 21:48 ` TyBreaker
@ 2004-05-28 21:56 ` TyBreaker
0 siblings, 0 replies; 9+ messages in thread
From: TyBreaker @ 2004-05-28 21:56 UTC (permalink / raw)
TyBreaker wrote:
> nikki_wire wrote:
>
>> With the output you generated with your script, I'd like to remove all
>> the spaces and split the data into 7 bit chunks starting from the end.
>> These 7 bit chunks would then be decoded back to hex. So for our
>> example: 00000000 01000000 10010101 10001011 00000101 11001101
>> 10010000 01110000 11101010 10000001 becomes:
>>
>> 1000000 => 40
>> 1010101 => 55
>> 1100001 => 61
>
>
> Sorry, lost you here, don't understand from what you said how you
> arrived at these 7-bit sequences.
Oh wait, just worked it out. What are you trying to achieve here with
all the changes in base and direction of bits etc? You're not getting
me to code an atomic bomb or an underwear detector by any chance are you?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little UNIX scripting challenge...
2004-05-27 15:23 A little UNIX scripting challenge nikki_wire
2004-05-28 5:22 ` TyBreaker
2004-05-28 11:26 ` nikki_wire
@ 2004-05-28 16:12 ` nikki_wire
2004-06-02 9:40 ` nikki_wire
2 siblings, 1 reply; 9+ messages in thread
From: nikki_wire @ 2004-05-28 16:12 UTC (permalink / raw)
Somehow I've messed up this thread - anyhow someone came up with a way
to do this - thanks Tybreaker!
I was wondering if maybe anyone could help me take this one step
further.
I'd like to take the output generated from Tybreaker's script and
format it as follows:
First I'd like to remove all the spaces and then read the binary
output backwards and convert each 7 bit section into hex.
eg: 01110000 11101010 10000001
will become:
1000000 => 40
1010101 => 55
1100001 => 61
etc etc....
Also, does anyone know a way to concatenate a file without any of the
character returns in the file - eg. make the output all stay on one
line?
Thanks!
Nikki
nikki_wire@yahoo.com (nikki_wire) wrote in message news:<60fdd9c9.0405270723.33f51cc3@posting.google.com>...
> Hello!
>
> I am a UNIX novice but I'd like to write a script to decode some
> output - I was wondering if anyone could help me out with it?
>
> Here's what I'd like to do.
>
> I have some HEX output. eg. 81 ea 70 90 cd 05 8b 95 40 00
>
> I'd like to convert that to strict 8 bit binary with a zero as the
> filler for the extra characters but starting from the last 2 digits
> and working backwards.
> So for the above it would become 00 40 95 8b 05 cd 90 70 ea 81 and
> then subsequently 00000000 01000000 10010101 10001011 00000101
> 11001101 10010000 01110000 11101010 10000001 (I think that's right!)
>
> Does anyone have a way to do this? If so I'd appreciate it!
>
> Thanks
>
> Nikki
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little UNIX scripting challenge...
2004-05-28 16:12 ` nikki_wire
@ 2004-06-02 9:40 ` nikki_wire
2004-06-02 23:44 ` TyBreaker
0 siblings, 1 reply; 9+ messages in thread
From: nikki_wire @ 2004-06-02 9:40 UTC (permalink / raw)
Well, if you know how to write an undewear detector, I'd be intrigued
to know...! Actually what this is for is to decode some data from one
of my company's applications - at the moment it's a prolonged manual
process.
Cheers for the start with it!
Nikki
nikki_wire@yahoo.com (nikki_wire) wrote in message news:<60fdd9c9.0405280812.730ddb8c@posting.google.com>...
> Somehow I've messed up this thread - anyhow someone came up with a way
> to do this - thanks Tybreaker!
>
> I was wondering if maybe anyone could help me take this one step
> further.
>
> I'd like to take the output generated from Tybreaker's script and
> format it as follows:
>
> First I'd like to remove all the spaces and then read the binary
> output backwards and convert each 7 bit section into hex.
>
> eg: 01110000 11101010 10000001
>
> will become:
>
> 1000000 => 40
> 1010101 => 55
> 1100001 => 61
>
> etc etc....
>
> Also, does anyone know a way to concatenate a file without any of the
> character returns in the file - eg. make the output all stay on one
> line?
>
> Thanks!
>
> Nikki
>
>
>
> nikki_wire@yahoo.com (nikki_wire) wrote in message news:<60fdd9c9.0405270723.33f51cc3@posting.google.com>...
> > Hello!
> >
> > I am a UNIX novice but I'd like to write a script to decode some
> > output - I was wondering if anyone could help me out with it?
> >
> > Here's what I'd like to do.
> >
> > I have some HEX output. eg. 81 ea 70 90 cd 05 8b 95 40 00
> >
> > I'd like to convert that to strict 8 bit binary with a zero as the
> > filler for the extra characters but starting from the last 2 digits
> > and working backwards.
> > So for the above it would become 00 40 95 8b 05 cd 90 70 ea 81 and
> > then subsequently 00000000 01000000 10010101 10001011 00000101
> > 11001101 10010000 01110000 11101010 10000001 (I think that's right!)
> >
> > Does anyone have a way to do this? If so I'd appreciate it!
> >
> > Thanks
> >
> > Nikki
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little UNIX scripting challenge...
2004-06-02 9:40 ` nikki_wire
@ 2004-06-02 23:44 ` TyBreaker
2004-06-04 8:53 ` nikki_wire
0 siblings, 1 reply; 9+ messages in thread
From: TyBreaker @ 2004-06-02 23:44 UTC (permalink / raw)
nikki_wire wrote:
> Well, if you know how to write an undewear detector, I'd be intrigued
> to know...! Actually what this is for is to decode some data from one
> of my company's applications - at the moment it's a prolonged manual
> process.
Well it's easy to remove the spaces to get you one long string of 1's
and 0's. Just remove the space immediately following the %.8d in my
final awk command. Then reverse the string using awk again in a similar
way to how I reversed the original hex list - the catch is use '' (null)
as the delimiter so that it separates each digits in the string. Are
you comfortable with doing this yourself? I'm at home sick today so I
don't have a Unix box to play with.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A little UNIX scripting challenge...
2004-06-02 23:44 ` TyBreaker
@ 2004-06-04 8:53 ` nikki_wire
0 siblings, 0 replies; 9+ messages in thread
From: nikki_wire @ 2004-06-04 8:53 UTC (permalink / raw)
Thanks for this - I'll have a crack in the next couple of days - I'll
be honest, I don't understand what you coded very well at all but I
guess this is a chance to learn!
If you do get a chance to post your own version that would be brill
but don't worry if not.
Cheers
Nikki
TyBreaker <tybreakerNO@SPAMhotmail.com> wrote in message news:<JDtvc.3122$rz4.2989@news-server.bigpond.net.au>...
> nikki_wire wrote:
> > Well, if you know how to write an undewear detector, I'd be intrigued
> > to know...! Actually what this is for is to decode some data from one
> > of my company's applications - at the moment it's a prolonged manual
> > process.
>
> Well it's easy to remove the spaces to get you one long string of 1's
> and 0's. Just remove the space immediately following the %.8d in my
> final awk command. Then reverse the string using awk again in a similar
> way to how I reversed the original hex list - the catch is use '' (null)
> as the delimiter so that it separates each digits in the string. Are
> you comfortable with doing this yourself? I'm at home sick today so I
> don't have a Unix box to play with.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2004-06-04 8:53 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-27 15:23 A little UNIX scripting challenge nikki_wire
2004-05-28 5:22 ` TyBreaker
2004-05-28 11:26 ` nikki_wire
2004-05-28 21:48 ` TyBreaker
2004-05-28 21:56 ` TyBreaker
2004-05-28 16:12 ` nikki_wire
2004-06-02 9:40 ` nikki_wire
2004-06-02 23:44 ` TyBreaker
2004-06-04 8:53 ` nikki_wire
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox