Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed to insert colon in a mac address

Tags:

regex

sed

I have a list of mac addresses in this format:

412010000018
412010000026
412010000034

I want this output:

41:20:10:00:00:18
41:20:10:00:00:26
41:20:10:00:00:34

I tried this, but did not work:

sed 's/([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/\1:\2:\3:\4/g' mac_list

How should I do it?

like image 711
cppcoder Avatar asked Jun 12 '12 06:06

cppcoder


1 Answers

This might work for you (GNU sed):

sed 's/..\B/&:/g' file
like image 150
potong Avatar answered Nov 08 '22 15:11

potong