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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert MAC Address format 1

Status
Not open for further replies.

moria6

MIS
Jul 11, 2000
30
0
0
US
I would like to ask for help in converting a MAC address in the format:

0000.0000.0000 (Cisco IOS)

to

00:00:00:00:00:00

Not picky about using sed or awk (or perl).


The CAT OS boxes are a bit easier for me because I only have to use sed to replace "-" with ":"

00-00-00-00-00-00 (CAT OS)


TIA!


maurie
 
One way (sed):
echo '0000.0000.0000' | sed 's!\.!!g;s!\(..\)!\1:!g;s!:$!!'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, PHV!

That does the trick and helps me be a little bit less of a sed newbie. ;)

Thanks again!


maurie
 
PHV

For the sake of us mere mortals could you explain your sed statement. I've no doubt it works but I can't make head nor tail of it!

Thanks

Ceci n'est pas une signature
Columb Healy
 
could you explain your sed statement
s!\.!!g
get rid of all dots
s!\(..\)!\1:!g
append a colon after each pair of digits
s!:$!!
get rid of last colon

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
So this would work on both IOS and CAT type MAC output:

sed 's!\-!!;s!\.!!g;s!\(..\)!\1:!g;s!:$!!'

remove all dashes
remove all dots
insert colon every two digits
remove last colon


HTH,

p5wizard
 
make that

sed 's!\-!!g;s!\.!!g;s!\(..\)!\1:!g;s!:$!!'

or better yet

sed 's![-.]!!g;s!\(..\)!\1:!g;s!:$!!'


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top