我有如下输出:
FA-7E 0 500009730007C118
FA-8E 0 500009730007C11C
FA-7F 0 500009730007C158
FA-10F 0 500009730007C164
我想把它翻译成:
FA-7E 0 50:00:09:73:00:07:C1:18
FA-8E 0 50:00:09:73:00:07:C1:1C
FA-7F 0 50:00:09:73:00:07:C1:58
FA-10F 0 50:00:09:73:00:07:C1:64
请告知。
答案 0 :(得分:2)
$ awk '{gsub(/../,"&:",$NF);sub(/:$/,"")}1' file
FA-7E 0 50:00:09:73:00:07:C1:18
FA-8E 0 50:00:09:73:00:07:C1:1C
FA-7F 0 50:00:09:73:00:07:C1:58
答案 1 :(得分:1)
Sed解决方案:
sed -e 's/\([0-9A-F]\{2\}\)/\1:/g' -e 's/:\([- ]\|$\)/\1/g'
第一个替换添加:在每对十六进制数字之后,第二个替换从第一列和行尾移除额外冒号。
答案 2 :(得分:0)
perl变体:
perl -pe 's/\w\w(?=\w+$)/$&:/g' file
答案 3 :(得分:0)
不是最好但有效:
perl -lane 'push @a,$F[2]=~/../g;$F[2]=join ":",@a;undef @a;print "@F"' your_file