The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
If Then Else Logic jadionne UNIX for Dummies Questions & Answers 7 11-23-2007 04:27 AM
cannot get the logic dineshr85 Shell Programming and Scripting 3 10-11-2007 08:34 AM
Strange Logic ganesh123 Shell Programming and Scripting 5 03-20-2007 05:08 PM
what the logic ramneek IP Networking 2 09-05-2005 08:42 AM
How do I start a program when I start my Computer? l008com UNIX for Dummies Questions & Answers 1 06-23-2002 09:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-01-2008
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
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


Code:
 120 : TXADDR  : 00000000

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

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

next when
Code:
 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

Code:
     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

Last edited by user_prady; 09-01-2008 at 01:28 AM..
  #2 (permalink)  
Old 09-01-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Should the data always be received in the order it was sent? If so, try this:


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


Last edited by Annihilannic; 09-01-2008 at 01:39 AM.. Reason: forgot the 'datafile'
  #3 (permalink)  
Old 09-01-2008
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by Annihilannic View Post
Should the data always be received in the order it was sent? If so, try this:


Code:
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

Last edited by user_prady; 09-01-2008 at 02:09 AM..
  #4 (permalink)  
Old 09-01-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Something like this? (not tested much)


Code:
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

  #5 (permalink)  
Old 09-01-2008
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by Annihilannic View Post
Something like this? (not tested much)


Code:
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

Code:
txdata[txaddr,++txindex[txaddr]]

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

Regards,
user_prady

Last edited by user_prady; 09-01-2008 at 03:29 AM..
  #6 (permalink)  
Old 09-01-2008
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by user_prady View Post
Thanks genious Annihilannic .. Really appriciate your logic..

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

Code:
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


Code:
     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

Code:
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
  #7 (permalink)  
Old 09-02-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Quote:
Originally Posted by user_prady View Post
Can You Please give a brief idea what does this statement for

Code:
txdata[txaddr,++txindex[txaddr]]

I guess this is a 2D array but when I print that only it gives me error.
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0