//View Tip #182
Similar Tips
» SVN resolve all conflicts
» Convert permissions to octal
» Crawl a web page for links
» Actively Monitor a File
» Using Perl instead of Sed


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Convert mac addresses such as 000000abde00 into 00:00:00:ab:de:00

awk '{for(i=10;i>=2;i-=2)$0=substr($0,1,i)":"substr($0,i+1);print}' macaddress_list
sed 's/\(..\)/\1:/g;s/:$//' macaddress_list

// sil at infiltrated.net

View Comments »


Add your comment

Comments are currently disabled
even easier:
sed -E "s/([0-9a-f]{2})/\1:/g;s/:$//"
Posted 2009-03-26 07:58:50
I needed this for WWPN (MAC-like) conversion:

# echo 201400a0b84778c0 | sed -e 's|\([a-f0-9A-F][a-f0-9A-F]\)|\1:|g' -e 's|:$||g'


Note: do not forget to check for capital letters.
Posted 2009-08-12 07:22:21
i forgot the lower->upper conversion for output consistency:

# echo 201400a0b84778c0 | sed -e 's|\([a-f0-9A-F][a-f0-9A-F]\)|\1:|g' -e 's|:$||g' | tr '[:lower:]' '[:upper:]'
Posted 2009-08-12 07:24:07

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit