DISCLAIMER:
This script is as is. I give no warranty it will work as you expected on your system. You are running it at your own risk. If something goes wrong because of this script, I bear no responsibility.
Language:
server# bash –version
GNU bash, version 3.00.16(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2004 Free Software Foundation, Inc.
Purpose:
You have a starting device number in hexadecimal format. You want to print out next n number of devices starting from given device number. You may also want to insert a blank line after certain number of dev numbers (say you wanted to create meta with certain number of hypers).
Usage:
Example 1: Print next 8 devices starting at 1F0
server# print_range.bash 1F0 8
1F0
1F1
1F2
1F3
1F4
1F5
1F6
1F7
Example 2: Print next 8 devices starting at 1F0, and insert a blank line after every 4 devs (a meta containing 4 hypers)
server# print_range.bash 1F0 8 4
1F0
1F1
1F2
1F3
1F4
1F5
1F6
1F7
server#
server# cat print_range.bash
#!/bin/bash
# A script to display next NN hex numbers given at command line
# To display one continuous dev list :
# ./print_range.bash 21AA 5 (display next 5 devices with 21AA being first dev)
# To display several list with an empty line after certain number of devs
# ./print_range.bash 21AA 8 4 (display next 8 devices with 21AA being first dev and an empty line after 4 devs)
# Read the given arguments and assign to first and last given value
firsthex=`echo $1 | tr "[:lower:]" "[:upper:]" `
range=$2
gap=$3
# Check whether the range is numeric
if [[ ! -z $range ]] ; then
range_check=`echo $range| tr -d "[0-9]"`
if [[ ! -z $range_check ]]; then
echo "ERROR - Range value $range is not an integer"
exit
fi
fi
# Check whether gap is numeric - check only if the value is provided
if [[ ! -z $gap ]] ; then
gap_check=`echo $gap| tr -d "[0-9]"`
if [[ ! -z $gap_check ]]; then
echo "ERROR - Gap value $gap is not an integer"
exit
fi
else
gap=0
fi
# Set up h2d function which will convert hex to dec and vice versa
function h2d {
echo "ibase=16; $@"|bc
}
function d2h {
echo "obase=16; $@"|bc
}
# Convert first number into dec
firstdec=`h2d $firsthex`
gapcount=1
## For numbers between the firstdec and lastdec, print the hex on screen
for ((i=1;i<=$range;++i))
do
echo `d2h $firstdec`
let "firstdec += 1"
if [[ "$gapcount" -eq "$gap" ]] ; then
echo
gapcount=1
else
let "gapcount += 1"
fi
done
No comments yet.