Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting in hex

Status
Not open for further replies.

hopwon

Technical User
Mar 7, 2007
6
ZA
I'm writing a script to create target and lun numbers for disks.
The script needs to start with a number and count to 7 printing the count. Then reset the second number to 0 and increment the first number and print the results.
It must be in hex too.
e.g.
0A 00
0A 01
0A 02
....
0A 07
0B 00
0B 01
0B 02 etc

I can do this with a long shell script but was hoping someone can suggest a more efficent way with AWK?

thanks
 
awk on AIX (dont know about others) doesn't seem to understand hex numbers in input so:

Code:
awk 'BEGIN{
 target=10; # would have liked: target=0xa;
 lun=0      # 0x00
 while (target <= 31) { # 0x1f
  while (lun <= 7) {    # 0x07
   printf "%02X %02X\n", target, lun
   lun++
  }
  target++
  lun=0
 }
}'


HTH,

p5wizard
 
Awesome! Thanks for this man it works exactly as i wanted.
Saved me loads of work!

Cheers
 
(korn) shell script isn't too long either:

Code:
(( tgt=10 ))
(( lun=0 ))
while (( tgt <= 31 ))
do
 while (( lun <= 7 ))
 do
  printf "%02X %02X\n" $tgt $lun
  (( lun=lun+1 ))
 done
 (( tgt=tgt+1 ))
 (( lun=0 ))
done


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top