When I do a snmpwalk of my router the mac address are not what I expected.
Then return looking like this
How would you convert them to 001c.c92a.b677 when a shell script?
When I do a snmpwalk of my router the mac address are not what I expected.
Then return looking like this
How would you convert them to 001c.c92a.b677 when a shell script?
Awful long but works:
echo "0:1c:c9:2a:b6:77"| tr -s ':' '\n'| sed 's/^.$/0&/'| tr -d '\n'| sed 's/\(....\)\(....\)\(....\)/\1\.\2\.\3\n/g'
001c.c92a.b677
Here is a pure shell solution using ksh93
#!/usr/bin/ksh93
MAC="0:1c:c9:2a:b6:77"
IFS=":" typeset -a array=($MAC)
outmac=""
for ((i = 0; i < 6; i++))
do
(( ${#array} < 2 )) && outmac="${outmac}0"
outmac="${outmac}${array}"
(( i < 5 && (i % 2) == 1 )) && outmac="${outmac}."
done
echo "$MAC --> $outmac"
which gives the following output
0:1c:c9:2a:b6:77 --> 001c.c92a.b677
Thanks for the responses.
I am on Solaris 10. This does not seem to work?
tr -d '\n'
??