Skip to content

Instantly share code, notes, and snippets.

@benjyiw
Created May 30, 2018 06:33
Show Gist options
  • Save benjyiw/a80a65608c4b1e37e9237d4e6e911255 to your computer and use it in GitHub Desktop.
Save benjyiw/a80a65608c4b1e37e9237d4e6e911255 to your computer and use it in GitHub Desktop.
Convert mac address to Cisco format (xxxx.xxxx.xxxx) and back (xx:xx:xx:xx:xx:xx)
#!/bin/bash
mac="$@"
if [[ ${mac} == ??:??:??:??:??:?? ]]; then
sed 's/\://;s/\:/./;s/\://;s/\:/./;s/\://' <<< ${mac}
elif [[ ${mac} == ????.????.???? ]]; then
sed 's/\.//g;s/\(..\)/\1:/g;s/:$//' <<< ${mac}
else
echo 'That does not appear to be a mac address, try harder'
exit 1
fi
@bwesemann-cxp
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment