How to Convert Hex value to Dec ?

Hi All,

I want to convert below Hex value to Dec value in each column .How to do it ? This data is in a 1 file.

4e20 0475
2710 010f
7530 69a2
7530 7e2f
4e20 02dd
7530 6299
4e20 0c0a
7530 69a2
4e20 0a0b
2710 0048
7530 7955
4e20 0d23
7530 622d
7530 9121
2710 001f
7530 7d3f
7530 7937
4e20 00df
7530 59e3
4e20 0cab
4e20 0a0b
7530 59e4
7530 59e5
7530 65ba
7530 fe15

thanks,

Nayanajith.

try this:

perl -pi -e 'printf ("%d", $_);' file

if you have gawk

awk --non-decimal-data '{print ("0x"$1)+0 " " ("0x"$2)+0}' file

output:

# awk --non-decimal-data '{print ("0x"$1)+0 " " ("0x"$2)+0}' file
20000 1141
10000 271
30000 27042
30000 32303
20000 733
30000 25241
20000 3082
30000 27042
20000 2571
10000 72
30000 31061
20000 3363
30000 25133
30000 37153
10000 31
30000 32063
30000 31031
20000 223
30000 23011
20000 3243
20000 2571
30000 23012
30000 23013
30000 26042
30000 65045

A python alternative:

#!/usr/bin/python
for line in open("file"):
	print "%d %d" %  ( int(line.split()[0],16) , int(line.split()[1],16) ) 

I don't have gawk.

if you have dc,

awk '{ 
      h1 = "echo 16i " toupper($1) " pq | dc"
      h2 = "echo 16i " toupper($2) " pq | dc"
      h1 | getline tmp1; close(h1)
      h2 | getline tmp2; close(h2)
      print tmp1 " " tmp2
}' "file"

If your shell has printf builtin (bash, ksh93, ash, etc.), you can do it without any external commands:

while read a b
do
  printf "%5d %5d\n" "0x$a" "0x$b" 
done < "$FILE"

If the file is very large, you may be better off using awk.

I don't know anything to do with programming,help me out,please.