can someone help me in converting hex streams to decimal values using perl script
Hex value:
$my_hex_stream="0c07ac14001676";
Every hex value in the above stream should be converted in to decimal and separated by comma.
The output should be: 12,07,172,20,00,22,118
The following works:
perl -e '
$hex="0c07ac14001676";
while($hex=~/(..)/g){
push @values, $1;
};
for (@values){
$_=hex($_);
}
print join(",",@values),"\n";'
12,7,172,20,0,22,118
1 Like
# echo "$my_hex_stream"|awk --non-decimal-data '{for(i=1;i<NF-1;i+=2){A=sprintf("%0d,","0x"$i$(i+1));print A}A=sprintf("%0d","0x"$(NF-1)$NF);print A
}' FS= ORS=
12,7,172,20,0,22,118
1 Like