The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



Thread: Hex Conversion
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-20-2007
insania insania is offline
Registered User
 

Join Date: Nov 2005
Posts: 22
Hex Conversion

I need to have my scripts import volume groups and mknod devices files. I have most of the script working but the device file needs to be in the format 0x??0000 (where the question marks are my HEX representations of the volume group number. I have the code below and the output it produces which would work great except anything that is only one charater will not work (I.E "1" needs to be "01", "a" needs to be "0a"). Any suggestions? And I can't use any perl code.

#!/bin/sh

for y in vg01 vg02 vg03 vg10 vg21 vg22 vg23
do
printf "%#x\n" $(echo ${y} | sed 's/^vg//') | sed 's/0x//'
done



Output:

1
2
3
a
15
16
17
Reply With Quote
Remove advertisements
!!
Forum Sponsor