need a logic to start with awk/ sh

Hi Friends,

  I got stuck where to start with ..

I ve a input file like below. where I want to compare write data with my read data .. The problem is that the read data should be compared with the lastest write data on that address.

Note- Both write data & read data are in the same file.
TXADDR & TXDATA means -write
RXADDR & RXDATA means - read

 120 : TXADDR  : 00000000

means at time 120 I am sending a TXADDR -00000000 & the data to be written are like below

     240 : TXDATA  0000000000000001
     280 : TXDATA  0000000000000002
     320 : TXDATA  0000000000000003
     360 : TXDATA  0000000000000004
     400 : TXDATA  0000000000000005

next when

 1042 : RXADDR  : 00000000 

comes It the time to read from that address 00000000 returns me the data what is written before i.e, the last one..

INPUT FILE

     120 : TXADDR  : 00000000
     240 : TXDATA  0000000000000001
     280 : TXDATA  0000000000000002
     320 : TXDATA  0000000000000003
     360 : TXDATA  0000000000000004
     400 : TXDATA  0000000000000005
    1042 : RXADDR  : 00000000
    1080 : TXADDR  : 00000020
    1200 : TXDATA  0000000000000011
    1240 : TXDATA  0000000000000012
    1280 : TXDATA  0000000000000013
    1320 : TXDATA  0000000000000014
    1321 : RXDATA  0000000000000001
    1360 : TXDATA  0000000000000015
    1361 : RXDATA  0000000000000002
    1401 : RXDATA  0000000000000003
    1441 : RXDATA  0000000000000004
    1481 : RXDATA  0000000000000005
    1880 : TXADDR  : 00000040
    2000 : TXDATA  0000000000000021
    2040 : TXDATA  0000000000000022
    2080 : TXDATA  0000000000000023
    2120 : TXDATA  0000000000000024
    2120 : TXDATA  0000000000000025

If there is some confusion with my explanation pls comment .

Thanks &
Regards,
user_prady

Should the data always be received in the order it was sent? If so, try this:

awk '/TX/ { print $NF }' datafile > sent
awk '/RX/ { print $NF }' datafile > received
diff sent received

Thanks for your reply..& Sorry If I misguided you..

No its not like that data is not recevied until unless I specify to read exclusively . Think of as a RAM( Read access Memory)

I writes to RAM by specifing TXADDR & TXDATA and I retrives the data when I specify that address with RXADDR , I get RXDATA ie, last written on that addresss.

Actually Wrrtting and reading are independent of each other.

Once I give TXADDR & TXDATA (5 burst - In INPUT FILE you can see five lines of input data contineously). Then after that I am going to Read those values when RXADDR comes ..

Suppose I am writting to the same address twice then reading from that address then it ll read the lastest value that is written to that address.

Thanks
user_prady

Something like this? (not tested much)

awk '
        /TXADDR/ { txaddr=$NF }
        /RXADDR/ { rxaddr=$NF }
        /TXDATA/ { txdata[txaddr,++txindex[txaddr]]=$NF }
        /RXDATA/ {
                if ($NF != txdata[rxaddr,++rxindex[rxaddr]]) {
                        print "rxdata " $NF " for address " rxaddr " does not match transmitted: " txdata[rxaddr,rxindex[rxaddr]]
                }
        }
' inputfile

Thanks genious Annihilannic .. Really appriciate your logic..

Can You Please give a brief idea what does this statement for

txdata[txaddr,++txindex[txaddr]]

I guess this is a 2D array but when I print that only it gives me error.

Regards,
user_prady

my friend Its seems to be not working for this case

INFILE

     120 : TXADDR  : 00000000
     240 : TXDATA  0000000000000011
     280 : TXDATA  0000000000000012
     320 : TXDATA  0000000000000013
     360 : TXDATA  0000000000000014
    1080 : TXADDR  : 00000000
    1200 : TXDATA  0000000000000001
    1240 : TXDATA  0000000000000002
    1280 : TXDATA  0000000000000003
    1320 : TXDATA  0000000000000004
    2002 : RXADDR  : 00000000
    2040 : TXADDR  : 00000020
    2160 : TXDATA  0000000000000011
    2200 : TXDATA  0000000000000012
    2240 : TXDATA  0000000000000013
    2280 : TXDATA  0000000000000014
    2281 : RXDATA  0000000000000001
    2321 : RXDATA  0000000000000002
    2361 : RXDATA  0000000000000003
    2401 : RXDATA  0000000000000004

OUTPUT

rxdata 0000000000000001 for address 00000000 does not match transmitted: 0000000000000011
rxdata 0000000000000003 for address 00000000 does not match transmitted: 0000000000000012
rxdata 0000000000000003 for address 00000000 does not match transmitted: 0000000000000013
rxdata 0000000000000004 for address 00000000 does not match transmitted: 0000000000000014

Here the in the above input file same address (i.e, in address 00000000 I am writting twice and reading the data once and the lastest data are matching with the read data but in my programme its saying not matching)

Pls give me a suggestion ..

Regards,
Pradyumna

Yes, it's a two-dimensional array indexed by the address and an index. The indices themselves are held in a second one-timensional array, txindex.

So to cater for your second situation, all you need to do is reset the txindex[txaddr] counter to 0 each time a new TXADDR is encountered. Similarly you can reset the rxindex[rxaddr] counter each time an RXADDR is encountered.

Thanks for your reply & valuable time .

Today morning I tried to reset the index . When I changed to txindex= 0, it throws me error but it should be txindex[txaddr] = 0 as you suggested & with that the programme goes smoothly..

Again Thanks a lot .. God Bless you..

Thanks for your reply & valuable time .

Today morning I tried to reset the index and I changed to txindex= 0, it throws me error but when it should be txindex[txaddr] = 0 as you suggested with that the programme goes smoothly..

Again Thanks a lot .. God Bless you..