awk to compare hex number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to compare hex number
# 1  
Old 10-26-2011
awk to compare hex number

Code:
$ awk 'BEGIN{ pat111=0x1000000002E3E02; snBegin=0x1000000002E3E01; if (pat111<=snBegin) printf "a\n"}'
a

Result is not correct.
Looks like the number is too big.
Any idea?
Thx!


Moderator's Comments:
Mod Comment Please use code tags <- click the link!

Last edited by zaxxon; 10-26-2011 at 04:23 AM.. Reason: code tags, see PM
# 2  
Old 10-26-2011
Looks like a bug in awk
Code:
awk 'BEGIN{ pat111=sprintf ("%d", 0x1000000002E3E02); snBegin=sprintf("%d",0x1000000002E3E01);print pat111;print snBegin; if (pat111<=snBegin) printf "a\n"}'

72057594040958464
72057594040958464
a

Code:
$ awk 'BEGIN{printf "%X", 72057594040958464}'
1000000002E3E00

$ awk 'BEGIN{printf "%X", 72057594040958465}'
1000000002E3E00

Code:
$ echo $((0x1000000002E3E02))
72057594040958466

$ echo $((0x1000000002E3E01))
72057594040958465

This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 10-26-2011
I believe this is an implementation limit, not a bug, i.e. these numbers are large for awk.

You may use Perl though:

Code:
perl -le'
  $pat111  =  0x1000000002E3E02; 
  $snBegin =  0x1000000002E3E01; 
  
  $pat111 <= snBegin
    and print " ... "
    '

This User Gave Thanks to radoulov For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh : split hex number group

Hi, sry for poor english I have a group of hex number as : 4D40:4D42 I want so split this group in a list as : 4D40,4D41,4D42 i don't know how i can do this in ksh Thanks (5 Replies)
Discussion started by: jocazh
5 Replies

2. Shell Programming and Scripting

Pass column number as variable to awk and compare with a string.

Hi All, I have a file test.txt. Content of test.txt : 1 vinay se 2 kumar sse 4 kishore tl I am extracting the content of file with below command. awk '$2 ~ "vinay" {print $0}' test.txt Now instead of hardcoding $2 is there any way pass $2 as variable and compare with a... (7 Replies)
Discussion started by: Girish19
7 Replies

3. Shell Programming and Scripting

Hex number sequence help

Need some help doing this ... with awk maybe Input 0DF6 0DF7 0DF8 0DF9 0DFA 0DFB 0DFC 0DFD 0DFF 0E00 0E01 0E02 0E03 0E04 0E05 0E06 (11 Replies)
Discussion started by: greycells
11 Replies

4. Shell Programming and Scripting

Compare Hex Value from CSV File

I have a one CSV File Contain Hex Value here is a sample file 6300, 0x0, 0x60d0242c6, , 0x728e5806, unnamedImageEntryPoint_0x728e5806, 0x728e$ 6300, 0x0, 0x60d024c52, , 0x728e8cb7, unnamedImageEntryPoint_0x728e8cb7, 0x728e$ 6300, 0x0, 0x60d025638, , 0x728e82da,... (2 Replies)
Discussion started by: rakesh_arxmind
2 Replies

5. Shell Programming and Scripting

Compare strings between 2 arrays and print number in AWK

Hi to everyone, Please some help over here. Hi have array a with 6 elements and array b with 3 elements as shown inside BEGIN{} statement. I need help to get the correct sintax (the part in red) to compare if string from array b is in array a and print the number related for each match.... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

6. Shell Programming and Scripting

awk to remove leading zeros for a hex number

Is it possible by using awk to remove leading zeros for a hex number? ex: 0000000011179E0A -> 11179E0A Thank you! (4 Replies)
Discussion started by: carloszhang
4 Replies

7. Shell Programming and Scripting

[awk]compare a number in a string with a list

Hi, I have a program written in awk and I want to extend it to do another task. My program is a list of CVS log reports of a repository. For each file, I have some fields. One of the fields is the comment field. I want to know how I can check if a comment (which is a free text field)... (8 Replies)
Discussion started by: sandeepk1611
8 Replies

8. Shell Programming and Scripting

awk conditional expression to compare field number and variable value

Hi, I'm trying to compare the value in a field to the value in a variable using awk. This works: awk '$7 == "101"'but this is what I want (and it doesn't work): value=101 awk '$7 == "$value"' Any help or insight on this would be great. Thanks in advance. (1 Reply)
Discussion started by: goodbenito
1 Replies

9. Shell Programming and Scripting

HEX number grouping

Guys, I am looking for a small script which generates HEX sequence. Input to the script is starting hex number - Group ID and number of members in a group and total groups. e.g: we are generating 2 groups with 4 Members each starting with hex number 036A. I should get o/p in following format. ... (5 Replies)
Discussion started by: dynamax
5 Replies

10. Shell Programming and Scripting

incremental addition of hex decimal number in one field

Hi I want to incremental add hex decimal number to a particula field in file eg: addr =123 dept1=0 addr = 345 dept2 =1 addr2 = 124 dept3 =2 . . . . . . addr3 =567 dept15 =f Is there any command which add... (8 Replies)
Discussion started by: diddi_linux
8 Replies
Login or Register to Ask a Question