//View Tip #182
Similar Tips
» Convert seconds to Hours, Minutes and Seconds
» Print until no match
» Kill matching processes without unnecessary greps and extra sh p
» Count files by type v2
» Get your IP address

 

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 »




Comments 

Add your comment

Comments are currently disabled
David
even easier:
sed -E "s/([0-9a-f]{2})/\1:/g;s/:$//"
Posted 2009-03-26 07:58:50
angelo
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'

output:
20:14:00:A0:B8:47:78:C0


Note: do not forget to check for capital letters.
Posted 2009-08-12 07:22:21
angelo
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