NAWK conversion of hexadecimal input to decimal output via printf, I am close I can feel it
I have searched and the answers I have found thus far have led me to this point, so I feel I am just about there.
I am trying to convert a column of hexadecimal to decimal values so that I can filter out via grep just the data I want. I was able to pull my original 3 character hex value and append 0x to the front but the printf statement seems not to work to convert it to decimal. I dumped my output to a file and have been trying to get it to convert so I can proceed on.
Here are the last lines snipped from my file, as it it large:
From the shell prompt I tried:
and get the proper output:
62
If I type:
I get nothing but zeroes as output:
I tested via:
and my output has the correct output from $1, but "%d\n" won't output the decimal equivalent:
So what am I missing? I have had it suggested that printf is different in awk than in the shell but that seemed wrong from what I read.
Last edited by PCGameGuy; 04-03-2012 at 07:20 PM..
Reason: Edited for clarity
Please post what Operating System and version you are running and what Shell you have.
I may not be able to help with the solution, but this basic information will help other posters.
Re-reading the original post it is hard to work out what you are trying to achieve.
Please post sample input data, sample matching output data and a brief description of the process.
Lateral thought.
Have you considered converting the search number in question to matching format hexadecimal and then using grep rather than converting all the hexadecimal values in the large file to decimal?
Lateral thought.
Have you considered converting the search number in question to matching format hexadecimal and then using grep rather than converting all the hexadecimal values in the large file to decimal?
Heh, that is actually what I have been pondering pretty heavily as an alternative actually.
My suggestion that end users learn hexadecimal before touching my script was denied, sadly.
How can I convert hexadecimal values to Binary from the second field to the end
Input:
WS-2 23 345 235
DT-3 45 4A3 000
pp-2 76 300 E4
Output:
WS-2 100011 1101000101 1000110101
DT-3 1000101 10010100011 000
pp-2 1110110 1100000000 11100100 (16 Replies)
Hi Guys,
Is it possible to convert the hexadecimal to Binary by unix command.....I could not figure out....
If I need to convert AF6D to binary...what could be the way to do?
Thanks in advance!!
---------- Post updated at 02:57 AM ---------- Previous update was at 02:42 AM ----------
I... (6 Replies)
Hi Experts,
Quick question:
I am trying to get the output with decimal and floating point but not working:
echo "20.03" | awk '{printf "%03d.2f\n" , $0 }'
020.2f
How to get the output as :
020.03
Thank you. (4 Replies)
printf "%X\n" "A"
41
printf "%X\n" "2"
2
Expected 32 (not 2).
Is there a "printf" which will output the hexadecimal value of a numeric character? (9 Replies)
Hello everybody,
I would like to understand why the printf function is returning me an octal value with this command :
printf %4.4d 0010 returns 0008
printf %4.4d 10 returns 0010
Thanks for help. (3 Replies)
Hi all,
I have a small script to convert my HexaDecimal Input to Decimal as output.
#!/bin/ksh
hd=00208060
dec=`printf %d $hd`
echo $dec
Output of the above program:
printf: 00208060 not completely converted
16
But my expected output is "2130016".
How can i acheive this.
I... (2 Replies)
Hi frnds :)
I need a small help...
I have a very long file containing 20 digits decimal number which i want to convert into the corresponding 16 digit hexadecimal values.
File looks like....
11908486672755551741
05446378739602232559
04862605079740156652
.
.
.
I tried the script
for i... (7 Replies)