replace variable with awk 
Author Message
 replace variable with awk

Hello,

i've got the following text file:
(hexadecimal values)

03/19/02 16:22:39 ECHO: 6B 05 04 03 80 90 A3 18 01 83 70 0B 81 30 36
03/19/02 16:22:40 HEX: EB 02 18 01 89
03/19/02 16:22:41 HEX: EB 03 1E 02 82 81
03/19/02 16:22:42 HEX: EB 07 29 06 02 03 13 10 16 38 4C 02 00 C3
03/19/02 16:22:55 ECHO: 6B 45 08 02 85 90
03/19/02 16:22:55 HEX: EB 4D 08 02 85 90
03/19/02 16:22:55 ECHO: 6B 5A

now i want to bitwise and the first variable after the ECHO: and HEX:
lines with the pattern 0x7F.

EB
7F              
-- &
6B

and replace this variable with the variable in the file, so that all
the variables after the ECHO: and HEX: are the same.

how can i do this in AWK?

thanks in advance,

Chris.



Sun, 05 Sep 2004 20:08:46 GMT  
 replace variable with awk

Quote:

>Hello,

>i've got the following text file:
>(hexadecimal values)

>03/19/02 16:22:39 ECHO: 6B 05 04 03 80 90 A3 18 01 83 70 0B 81 30 36
>03/19/02 16:22:40 HEX: EB 02 18 01 89
>03/19/02 16:22:41 HEX: EB 03 1E 02 82 81
>03/19/02 16:22:42 HEX: EB 07 29 06 02 03 13 10 16 38 4C 02 00 C3
>03/19/02 16:22:55 ECHO: 6B 45 08 02 85 90
>03/19/02 16:22:55 HEX: EB 4D 08 02 85 90
>03/19/02 16:22:55 ECHO: 6B 5A

>now i want to bitwise and the first variable after the ECHO: and HEX:
>lines with the pattern 0x7F.

>EB
>7F              
>-- &
>6B

>and replace this variable with the variable in the file, so that all
>the variables after the ECHO: and HEX: are the same.

>how can i do this in AWK?

>thanks in advance,

>Chris.

One way would be to define an array lookup table in a BEGIN section.

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Mon, 06 Sep 2004 07:24:26 GMT  
 replace variable with awk

Quote:

> ... i want to "bitwise and" the first variable ...with the pattern 0x7F.
> ... and replace this variable with the variable in the file

If you have gawk 3.1 , try:

$3 ==  "ECHO:" || $3 == "HEX:" {$4 = sprintf( "%02X", and( strtonum(
"0x" $4 ) , 0x7f ) ) }
{ print }

Else try:

$3 ==  "ECHO:" || $3 == "HEX:" { $4 = sprintf( "%02X", And( hex_bin(
$4 ) , hex_bin( "7f" ) ) ) }
{ print }

function And( a,b    ,c,p ) {           # 2000-03-10 JRP
        for( p = 1 ; a != 0  ||  b != 0 ; p += p )
        {
                if ( a % 2 && b % 2 ) c += p
                a = int( a / 2 ); b = int( b / 2 )
        }
        return( c )

Quote:
}

function hex_bin(s,    b,c) {           # 2002-01-08 JRP
    for( b = 0; c = substr(s,1,1); s = substr(s,2) )
        b = 16*b + index( "123456789abcdef0000000000ABCDEF", c ) % 16
    return(b)

Quote:
}

Jurgen


Mon, 06 Sep 2004 16:08:35 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. awk variables --> shell variables

2. Replacing a string from an input file within awk script

3. How to replace one or two words with one word with one line of awk code

4. 2-file awk search-and-replace

5. Window's 2000 Global Find and Replace Solution using awk

6. Sed/AWK - replace positions in multiple lines.

7. awk "search and replace"

8. Replace character by awk

9. Problem replacing [ and ] in AWK (HP-UH10.20)

10. Replacing text using awk (but in a c shell)

11. fast-loading lisp sought to replace awk and zsh

12. fast-loading lisp sought to replace awk and zsh

 

 
Powered by phpBB® Forum Software