convert from hex to decimal part of sentence

Hi all,

I would like your help please with the following issue:
I have a file with a lot of rows (about 10 different fields) and I would like the awk command print the same rows but with fields 7 & 8 joind together and (they are in Hex value) converted from hex to decimal, is it possible ?
example of 2 rows in the file:
2008-11-08 full_ID NET:ROW 0000 01 a0 [b]45 5b [/b]5a 03
2008-11-08 full_ID NET:ROW 0000 02 00 [b]a3 56 [/b]b5 01

I want the rows above to go through the following steps:
2008-11-08 full_ID NET:ROW 0000 01 a0 [b]455b[/b] 5a 03
2008-11-08 full_ID NET:ROW 0000 02 00 [b]a356[/b] b5 01

2008-11-08 full_ID NET:ROW 0000 01 a0 [b]17755[/b] 5a 03
2008-11-08 full_ID NET:ROW 0000 02 00 [b]41814[/b] b5 01

Comments

  • Here's a short program to provide a method for you. You should be able to expand it as you need:

    [code]
    #include

    int main()
    {
    char line1[50] = "2008-11-08 full_ID NET:ROW 0000 01 a0 45 5b 5a 03";
    char w1[10], w2[10], w3[10], w4[10], w5[10], w6[10], w7[10], w8[10];
    int i1, i2;

    sscanf(line1, "%s %s %s %s %s %s %x %x %s %s", &w1, &w2, &w3, &w4, &w5, &w6, &i1, &i2, &w7, &w8);

    printf("%s %s %s %s %s %s %d %s %s
    ", w1, w2, w3, w4, w5, w6, i1*256+i2, w7, w8);

    return 0;
    }
    [/code]
    (Compiled with GCC)

    Take Care,
    Ed
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion