把 0024.b20b.693f 地址 转换成 00:24:b2:0b:69:3f
1.点号分隔的
[[email protected] ~]# echo "0024.b20b.693f" | sed -r ‘s/\b(..)(..)\b/\1:\2/g;s/\./:/g‘
00:24:b2:0b:69:3f
2.若是冒号分隔的,把 0024:b20b:693f 转换成
00:24:b2:0b:69:3f 最后的. 替换成:可以去掉了;
[[email protected] ~]# echo "0024:b20b:693f" | sed -r ‘s/\b(..)(..)\b/\1:\2/g‘
00:24:b2:0b:69:3f
3.-r 扩展正则表达式的另一种匹配方法
[[email protected] ~]# echo "0024.b20b.693f" | sed -r ‘s/\b([0-9af]{2})([0-9a-f]{2})\b/\1:\2/g;s/\./:/g‘
00:24:b20b:69:3f
[[email protected] ~]#
时间: 2024-10-14 03:09:04