Shell 使用awk或sed将十六进制转换为十进制

Shell 使用awk或sed将十六进制转换为十进制,shell,scripting,sed,awk,Shell,Scripting,Sed,Awk,我有这样一个数据,用逗号分隔: 18:22:05,OtherOMoperation,BatuAmpar,BatuAmparMG1,2fe3,c7b1 18:22:05,OtherOMoperation,BatuAmpar,BatuAmparMG2,2fe3,c7b2 18:22:05,OtherOMoperation,BatuAmpar,BatuAmparMG3,2fe3,c7b3 03:25:55,Othercauses,N_Pancamukti,N_PancamuktiMG1,2f50,c7

我有这样一个数据,用逗号分隔:

18:22:05,OtherOMoperation,BatuAmpar,BatuAmparMG1,2fe3,c7b1
18:22:05,OtherOMoperation,BatuAmpar,BatuAmparMG2,2fe3,c7b2
18:22:05,OtherOMoperation,BatuAmpar,BatuAmparMG3,2fe3,c7b3
03:25:55,Othercauses,N_Pancamukti,N_PancamuktiMG1,2f50,c775
03:25:55,Othercauses,N_Pancamukti,N_PancamuktiMG2,2f50,c776
我需要将最后两列转换为十进制,如下所示:

18:22:05,OtherOMoperation,BatuAmpar,BatuAmparMG1,12259,51121
18:22:05,OtherOMoperation,BatuAmpar,BatuAmparMG2,12259,51122
18:22:05,OtherOMoperation,BatuAmpar,BatuAmparMG3,12259,51123
03:25:55,Othercauses,N_Pancamukti,N_PancamuktiMG1,12112,51061
03:25:55,Othercauses,N_Pancamukti,N_PancamuktiMG2,12112,51062
我已经试过了:
cat | nawk-F,'{printf“%d\n”,$1}'

我只得到零作为输出:
0 0 0 0 0 0 0 0 0使用Perl时:

perl -lpe 's/([^,]*),([^,]*)$/hex($1).",".hex($2)/e' input
输出:

在呆呆的眼神中也有相似之处:

gawk --non-decimal-data -F, '
      BEGIN{OFS=FS}{for(i=5;i<7;i++) $i=sprintf("%d","0x"$i)}1' input
gawk——非十进制数据-F,'

开始{OFS=FS}{for(i=5;我已经在谷歌上搜索过了吗?嗯,你的awk比我建议的要好得多,所以让我们删除我的答案。+1
gawk --non-decimal-data -F, '
      BEGIN{OFS=FS}{for(i=5;i<7;i++) $i=sprintf("%d","0x"$i)}1' input