I realized, that this is can't be done so easely with Solaris AWK. I found an other NAWK Script on the Internet which can do this but i have no idea how implement this in the main script.
Here is the conversion script:
Code:
BEGIN { for(i=0;i<10;i++) decv[i]=i;
decv["a"]=10;decv["b"]=11;decv["c"]=12;decv["d"]=13;
decv["e"]=14;decv["f"]=15;
decv["A"]=10;decv["B"]=11;decv["C"]=12;decv["D"]=13;
decv["E"]=14;decv["F"]=15
}
function hex(x) {
value = 0;
i = 1;
n=length(x);
while ( n > 0 ) {
value = 16*value + decv[substr(x,i,1)];
n--;
i++;
}
return value
}
{printf("%12.0f\n",hex($1))}
Would be great if someone can help me.
Bye
Michael
Moderator's Comments:
Please use CODE tags as required by forum rules!
Last edited by RudiC; 05-08-2018 at 08:10 AM..
Reason: Added CODE tags, removed color abundance.
It always helps if people in here see WHAT and HOW is going wrong. So, the input to the two questionable lines as well as the resulting output / value and / or error messages would be valuable. On first sight, with my awk version (mawk 1.3.3 Nov 1996), the conversion is done correctly.
Quote:
Originally Posted by Don Cragun
If you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk.
Hi, you're absolut right, sorry for forgetting.
There were no special error messages except this:
Code:
bash-3.2# /script/fragmentation.sh tempool/data
There are 788 files.
There are 86526 blocks and 0 fragment blocks.
awk: division by zero
record number 105858
bash-3.2#
what should be ok when the Pool is not fragmented.
Because this script never found any fragmention even on filesystems which are fragmented for sure i checked the awk statement line by line. To check the conversion of the two vars
so the result should be the decimal output of the HEX number 26546fa00 and the decimal output of the sum of 26546fa00 and 800
So i removed the "+0" in the Statement
Code:
this_block = ("0x"fields[2])+0;
and then there were numbers... but only those hexadecimal numbers without letters. Next i investigated the net and found several Posts with the same Problem on Solaris awk. The solution is to use this extra function described above but i don't have any idea how to implement this in this awk-oneliner.
The split($3, fields, ":"); with your input line L0 0:26546fa00:800 4000L/800P F=10 B=308653/308653 should have 4000L/800P in fields[1] and leave fields[2] and [3] empty... which explains the printf result perfectly.
EDIT: If I use above and do it for $2, it prints perfectly reasonable numbers:
The output of firstHex2Dec und secondHex2Dec should be decimal 10293499392 and 2048 now but it is "0" because the "+0" seemes to overwrite the var.
Now i remove the "+0"
Hi , I have a file which contains text like
A|Mau|Code|12|Detail
B|Mau|Code|20|Header
I want to write a command using awk which will output
A|Mau|Code|12.00|Detail
B|Mau|Code|20.00|Header
I used a command like awk -F"|" {printf "%s|%s|%s|%.2f|%s",$1,$2,$3,$4,$5}' which does the... (4 Replies)
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)
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 (2 Replies)
Hello,
I need an awk script to receive a variable that's an decimal value such as 009 or 031 and then convert this value to an ascii character to use as the FS (field separator for the input file).
For example,
009 should be converted to an ascii tab
031 should be converted to an ascii... (1 Reply)
Please Help Me! about the problem down under.
I have 2 files with nearly the same characteristics, I have to convert one to the other format or the other format to one's format. I want to write it with awk.
The first file contain lines like this:
300000001#A#Y#Y#Y#Y
The other file contain... (4 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)