Skip to content

Instantly share code, notes, and snippets.

@Neo2SHYAlien
Forked from benjyiw/convert-mac
Last active January 11, 2021 15:15
Show Gist options
  • Select an option

  • Save Neo2SHYAlien/02087d20362512ac2e69ca2fb12cb9ee to your computer and use it in GitHub Desktop.

Select an option

Save Neo2SHYAlien/02087d20362512ac2e69ca2fb12cb9ee 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'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment