歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Linux shell mac 地址轉換 convert with sed

Linux shell mac 地址轉換 convert with sed

日期:2017/3/1 9:36:19   编辑:SHELL編程

Linux shell mac 地址轉換 convert with sed

把 0024.b20b.693f 地址 轉換成 00:24:b2:0b:69:3f

1.點號分隔的

[root@linuxidc-mpc ~]# 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 最後的. 替換成:可以去掉了;

[root@linuxidc-mpc ~]# echo "0024:b20b:693f" | sed -r 's/\b(..)(..)\b/\1:\2/g'
00:24:b2:0b:69:3f

3.-r 擴展正則表達式的另一種匹配方法

[root@linuxidc-mpc ~]# 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
[root@linuxidc-mpc ~]#

Shell編程淺析 http://www.linuxidc.com/Linux/2014-08/105379.htm

Linux Shell參數替換 http://www.linuxidc.com/Linux/2013-06/85356.htm

Shell for參數 http://www.linuxidc.com/Linux/2013-07/87335.htm

Linux/Unix Shell 參數傳遞到SQL腳本 http://www.linuxidc.com/Linux/2013-03/80568.htm

Shell腳本中參數傳遞方法介紹 http://www.linuxidc.com/Linux/2012-08/69155.htm

Shell腳本傳遞命令行參數 http://www.linuxidc.com/Linux/2012-01/52192.htm

Linux Shell 通配符、轉義字符、元字符、特殊字符 http://www.linuxidc.com/Linux/2014-10/108111.htm

Copyright © Linux教程網 All Rights Reserved