Visit Our UNIX and Linux User Community


Hex number sequence help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Hex number sequence help
# 1  
Old 09-12-2013
Hex number sequence help

Need some help doing this ... with awk maybe

Input

Code:
0DF6
0DF7
0DF8
0DF9
0DFA
0DFB
0DFC
0DFD
0DFF
0E00
0E01
0E02
0E03
0E04
0E05
0E06
0E07
0E08
0E09
0E0C
0E0D
0E0E
0E0F
0E10
0E14


Ouput
Code:
 
0DF6:0DFD
0DFF:0E09
0E0C:0E10
0E14


Basically i need to shorten the list by printing all the ranges which are in sequence

Thanks
# 2  
Old 09-12-2013
Try

Code:
$ awk 'NR==1{S=strtonum( "0x" $1 );P=$1}
         NR>1{K=strtonum( "0x" $1 );if((K - S) == 1){S=K;T=$1}else{print P":"T;P=$1;S=K}}END{if(P==$1){print P}}' file

0DF6:0DFD
0DFF:0E09
0E0C:0E10
0E14

# 3  
Old 09-12-2013
Thanks .... ! this is only working for the example i gave ....

Like in another example


Code:
 
0DE1
0DE2
0DE3
0DE4
0DE5
0DE6
0DE7
0DE8
0DE9
0DEA
0DEB
0DEC

Output should be ... 0DE1:0DEC

or

Code:
 
 
0DD5
0DD6
0DD7
0DD8
0DDA
0DDB
0DDC
0DDD
0DDE
0DDF



Output should be ...

Code:
 
0DD5:0DD8 
0DDA:0DDF

Not getting this output ... also this is on solaris which does have GAWK needed for strtonum function
# 4  
Old 09-12-2013
Sorry I've missed few steps.

now try

Code:
awk 'NR==1{S=strtonum( "0x" $1 );P=$1}
    NR>1{K=strtonum( "0x" $1 );if((K - S) == 1){S=K;T=$1}else{print P":"T;P=$1;S=K}}
    END{if(T==$1 && P!=$1){print P":"T}if(P==$1){print P}}' file

This User Gave Thanks to pamu For This Post:
# 5  
Old 09-12-2013
Thanks again .... it works in all cases except this one ...

Code:
 
0DDB
0DDC
0DDD
0DDE
0DDF
0DE1
0DE4
0DE5
0DE6
0DE7
0DE8

The output should be
Code:
 
0DDB:0DDF
0DE1
0DE4:0DE8

but its getting this ...
Code:
 
0DDB:0DDF
0DE1:0DDF
0DE4:0DE8


Also ... can we pls get a "nawk" version of this ... thanks
# 6  
Old 09-12-2013
What do you mean by 'nawk version'? A version which doesn't use GNU awk features like strtonum?
# 7  
Old 09-12-2013
Right .... I wanted to use this on Solaris which does not have GAWK and thus cannot use strtonum function .... thx

Previous Thread | Next Thread
Test Your Knowledge in Computers #936
Difficulty: Easy
The echo request ("ping") is an ICMP/ICMP6 message.
True or False?

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

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

3. Shell Programming and Scripting

How to take the missing sequence Number?

Am using unix aix KSH... I have the files called MMRR0106.DAT MMRR0206.DAT MMRR0406.DAT MMRR0506.DAT MMRR0806.DAT .... ... MMRR3006.DAT MMRR0207.DAT These files are in one dircetory /venky ? I want the output like this ? Missing files are : MMRR0306.DAT MMRR0606.DAT... (7 Replies)
Discussion started by: Venkatesh1
7 Replies

4. Shell Programming and Scripting

Perl : print the sequence number without missing number

Dear Perl users, I need your help to solve my problem below. I want to print the sequence number without missing number within the range. E.g. my sequence number : 1 2 3 4 5 6 7 8 11 12 13 14 my desired output: 1 -8 , 11-14 my code below but still problem with the result: 1 - 14 1 -... (2 Replies)
Discussion started by: mandai
2 Replies

5. Shell Programming and Scripting

awk to compare hex number

$ 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! Please use code tags <- click the link! (2 Replies)
Discussion started by: carloszhang
2 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

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

8. Shell Programming and Scripting

Hex numbering sequence

Friends, 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 a group should have and total groups. e.g: Here we are generating 2 groups with 4 Members each starting with hex 036A. Output: Group ID 036A,... (5 Replies)
Discussion started by: dynamax
5 Replies

9. Shell Programming and Scripting

Changing the sequence number

Hi, I have a data as follow: 1 400 2 239 3 871 4 219 5 543 6 ... 7 ... .. ... .. ... 99 818 100 991 I want to replace the sequence number (column 1) that start from 150. The output should like this: 150 400 151 239 (3 Replies)
Discussion started by: nica
3 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

Featured Tech Videos