No, what is wanted is 15. We want 0+"0xf" to be treated as a number with hexadecimal value 0xf that is to be printed as the unsigned decimal number 15.
This, however does produce correct output.
1. this emulates your approach - prepending "0x" to a hex number
2. it does produce correct output, I believe.
3. So, is it feasible to consider printf
sed or awk to pipe (or process substitution) prepended data to printf ?
data to printf?
Is there some reason we must only use awk to output
The submitter's original script used cat once and awk twice before doing the conversion from hex to decimal. I cut that back to just one awk, but clearly there is no need for awk here either. We can do it all with shell built-ins...
In theory, this script should work with /bin/sh, /bin/ksh, /bin/bash, and /usr/xpg4/bin/sh, but I don't know if the printf built-in in all of those shells will recognize hexadecimal string values (and Jim didn't say which shell he was using for the results he showed us in post #10 in this thread).
Let's compare your code (reformatted to be more easily seen on a normal screen):
and the code I suggested:
Your code requires that a shell be exec'ed to run your script, that cat be exec'ed to read your input file, and that awk be exec'ed to discard empty lines found in your input file.
My code requires that a shell be exec'ed to run my script. Note that the exec operation is a relatively EXTREMELY slow operation on UNIX and Linux systems.
Your script has cat read the entire contents of your input file, write the entire contents of your input file, has awk read the entire contents of your input file and write all non-blank lines in your input file, and has the shell read all non-blank line in your input file and write parts of those non-empty lines in a different format.
My script reads your input file once and writes parts of non-empty lines in a different format.
Your script reads 15 fields (named a through o) and never uses $c, $k, $l, $m, $n, or $o.
My script reads the same data, but uses the name junk for data that will not be used by the script. It uses ffield# as the names of the fields it does use. (If headings had been supplied on the sample input, I would have used variables names related to the field names.)
Your script uses %d as the format specifier when printing the converted hexadecimal values. My uses %u. By definition, hexadecimal values are unsigned. But for the sample data provided, the output will be identical. If some of your input data contains a sixteen hexadecimal digit value with the highest order hexadecimal digit being 8 or greater, your script will print it as a negative decimal value while my script will print it as a positive decimal value.
You seem to believe that:
is needed to get rid of the empty lines in your input file. I believe that:
is a much simpler and much more efficient way to ignore empty lines in your input file and it still would be if you used the much more efficient:
without the cat.
Unfortunately, now that I've tried to answer your original question:
Quote:
Hello Don, Finally I could get the results but not satisfied, looking to reduce the complexity in code:
about the complexity of your code, you have changed the question to:
Quote:
Hello Don, Finally I could get the results now looking to subtract coloumn3 with coloumn 4 in code:
and I don't know what that means. How do you subtract MET with a hexadecimal value like 00000000fbfa0000? And, if you did subtract field 3 from field 4 or subtract field 4 from field 3, what different output are you hoping to produce as a result? Does the difference replace field 3 or field 4, or is another output field supposed to be created?
Hi ,
seq can be 0...128
int windex = seq / 8;
int bindex = seq % 8;
unsigned char bitvalue = '\x01' << (7-bindex) ;
bpv.bitmapvalue = bitvalue;
This is the part of a program to convert decimal to bitmap value of hexadecimal.
I want this to change to convert only to... (1 Reply)
Hi,
I want to convert two hexadecimal numbers to decimal using unix command line.
1cce446295197a9d6352f9f223a9b698
fc8f99ac06e88c4faf669cf366f60d
I tried using
`echo "ibase=16; $no |bc`
printf '%x\n' "1cce446295197a9d6352f9f223a9b698"
but it doesn't work for such big number it... (4 Replies)
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... (10 Replies)
I have a text file of alphanumeric values listed one by one. I have to convert them to hexadecimal equivalents for each character seperated by ":" in Unix bash shell script. For example, 12345678 has to be converted to 31:32:33:34:35:36:37:38 (10 Replies)
Hi,
Here is my script to read a file into array:
awk -F '+' '
# load first file into array indexed by fields 1 and 2
NR == FNR {
file1nr = FNR
for (i=3; i<NF; i++) {
file1 = $i
}
I have this... (5 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 ,
i need a script to convert number into hexadecimal base
for example: 237=>ED
it s very important for me thank you in advance for you help (5 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)