script question

linuxperson used Ask the Experts™
Can you please help me write a shell script for the following

when I execute the following i should be getting this output as follows

I need to take this argument and split the 0xffffff00 as follow

ff ff ff 00 -->   (how do i convert this to this way)

 $ ./ -hex
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This was fun to figure out and I learned a lot.  I am sure there might be a better way to do this, but seems to work.

Here is my test:
$ ./
Here is the conversion

Here is the code I used:
ARG1=`echo $1 | cut -d/ -f2 | tr '[:lower:]' '[:upper:]'`
pair=($(echo $ARG1|sed  's/\(..\)/\1 /g'))

p1="$(echo -e "ibase=16; ${pair[1]}" | bc)" 
p2="$(echo -e "ibase=16; ${pair[2]}" | bc)"
p3="$(echo -e "ibase=16; ${pair[3]}" | bc)"
p4="$(echo -e "ibase=16; ${pair[4]}" | bc)"

echo "Here is the conversion"
echo $p1\.$p2\.$p3\.$p4

Open in new window

Hi linuxperson,

I'm not totally clear on the bottom line of your question, but if you want to take this as input:
and convert it to this:
(as savone seems to think), then you could do it in Perl like this:
    echo "" | perl -ne '/0x(.+)/; map{push @dec, hex} unpack "(A2)*",$1; print join(".",@dec)'

But if you really want a shell solution, then savone's might be the way to go.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial