awk script automation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script automation
# 8  
Old 10-28-2013
It should be done before END block. As you know In END block you are printing so..when FNR or NR reaches last line it will get printed so you get output only once.
# 9  
Old 10-28-2013
Yes I agree but I'm still getting one sentence. Also, how do we get hold of the src that we are calculating for. So in the print statement, we can use the value. I think we need to add the each src & dst in the array and have a for loop in the END block !!!. Or use key map ????

---------- Post updated at 01:20 PM ---------- Previous update was at 12:59 PM ----------

Code:
BEGIN {
  
  num_samples = 0;
  total_delay = 0;
  avg_delay=0;
}


/^\+/ && $9~/^2\..*/ && $10 {
    t_arr[$12] = $2;
};



/^r/&& $9~/^2\..*/ && $10{
    if (t_arr[$12] > 0) {
      num_samples++;
      delay = $2 - t_arr[$12];
    total_delay += delay;
    };
};

  avg_delay = total_delay/num_samples;
 
  print "Average end-to-end " avg_delay ;

  
  
  
END{
  #avg_delay = total_delay/num_samples;
  #print "Average end-to-end transmission delay is --> " avg_delay  " seconds";
 
};


Getting syntax error !!!
# 10  
Old 10-28-2013
Quote:
Originally Posted by ENG_MOHD
Yes I agree but I'm still getting one sentence. Also, how do we get hold of the src that we are calculating for. So in the print statement, we can use the value. I think we need to add the each src & dst in the array and have a for loop in the END block !!!. Or use key map ????
Quote:
Originally Posted by ENG_MOHD
END{
#avg_delay = total_delay/num_samples;
#print "Average end-to-end transmission delay is --> " avg_delay " seconds";
};
Getting syntax error !!!
Here you defined END block what is there inside except comment ??
so this is one reason for syntax error

Have a look here
Code:
$ echo Demo | awk 'END{print}'
Demo
$ echo Demo | awk 'END{#print}' 
awk: cmd. line:1: END{#print}
awk: cmd. line:1:      ^ syntax error

I am bit confused about the input and the output you expect, and also I didn't understand relationship with input you provided. And I noticed that you are again and again modifying your post..if you want to print soon after num_samples becomes non zero you can try like this, which prints as you expected in #7 post

Code:
awk '

$1 ~ /^\+/ && $9~/^2\..*/ && $10 {
                                          t_arr[$12] = $2;
                                  }

$1 ~ /^r/  && $9~/^2\..*/ && $10   {
                        if (t_arr[$12] > 0) {
                                      num_samples++
                                      delay = $2 - t_arr[$12]
                                      total_delay += delay
                                    }
                            }
num_samples{
            avg_delay = total_delay/num_samples
            print "Average end-to-end transmission delay", $9, "to", $10, "is", avg_delay  " seconds"
            num_samples=0         
        
           }' file

Code:
Average end-to-end transmission delay 2.4 to 5.4 is 0.024128 seconds
Average end-to-end transmission delay 2.4 to 5.4 is 0.048256 seconds
Average end-to-end transmission delay 2.4 to 5.4 is 0.072384 seconds


Last edited by Akshay Hegde; 10-28-2013 at 03:44 PM..
# 11  
Old 10-28-2013
Well, First of all I'd like to thank you for being patient and helpful.
I have updated my post many times based on your questions( thank you) to make obvious and clear.

Now, the latest code you have provided is close to what I'm after. However, this is what I have noticed:

1) The time difference (avg_delay) is increasing linearly which means we need to reset . I did reset total_delay=0 after resetting the num_samples.

2) When I used avg_delay, I was trying to get the average for every unique communication. The unique communication is defined when unique source -->unique destination. for example after I modified the code I got something like:
Code:
Average end-to-end transmission delay 2.5 to 6.5 is 4.34506 seconds
Average end-to-end transmission delay 2.5 to 6.5 is 4.37405 seconds
Average end-to-end transmission delay 2.6 to 6.6 is 4.40288 seconds
Average end-to-end transmission delay 2.6 to 6.6 is 4.43337 seconds
Average end-to-end transmission delay 2.7 to 6.7 is 4.46386 seconds
Average end-to-end transmission delay 2.7 to 6.7 is 4.49602 seconds
Average end-to-end transmission delay 2.0 to 6.0 is 4.52335 seconds
Average end-to-end transmission delay 2.0 to 6.0 is 4.55234 seconds
Average end-to-end transmission delay 2.0 to 6.0 is 4.58133 seconds
Average end-to-end transmission delay 2.0 to 6.0 is 4.61199 seconds
Average end-to-end transmission delay 2.8 to 6.8 is 4.64062 seconds
Average end-to-end transmission delay 2.8 to 6.8 is 4.67091 seconds

If the code was calculating correctly, I shouldn't get :
Code:
Average end-to-end transmission delay 2.0 to 6.0 is 4.52335 seconds
Average end-to-end transmission delay 2.0 to 6.0 is 4.55234 seconds
Average end-to-end transmission delay 2.0 to 6.0 is 4.58133 seconds
Average end-to-end transmission delay 2.0 to 6.0 is 4.61199 seconds

, instead I should get (4.55234 + 4.58133 +4.61199 )/3 , where 3 is number of samples and final line should look like:

Average end-to-end transmission delay 2.0 to 6.0 is 4.581887


Generally, I have two main conditions:
condition 1: if the condition true, the current time ( $2) will be recorded in an array[$12]. The index of the array is $12 which a unique ID for each unique communication. Therefore, I will end up for time recorded for each unique communication.

Condition2: will check the time or the unique ID and subtract it from the current time.

Total delay is incremented by the calculated delay ( assuming it is the same unique communication. I code worked if I specified the src and dst, so I'm assuming there would no change in the logic in case of automation.

I hope I make it clear !! this time
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automation Script for Oracle

Hi, As a Oracle Developer, I am writing many Procedures,Functions and Packages. Facing Many optimization issue after writing these Database objects. Trying to tune it manually. Can we write any Shell/Perl/Python script to Optimize these Database objects instead of doing manual check and... (1 Reply)
Discussion started by: vasuvv
1 Replies

2. Shell Programming and Scripting

Automation script

Hello All , I came across a tricky solution to devolop . Here is a part of the requirement automation . I have different set of server say : Web ( has 4 servers under it ) , App ( has 4 servers under it ) , DB ( has 2 servers under it ) Above each i have different load balancers , Say : Web... (4 Replies)
Discussion started by: radha254
4 Replies

3. Shell Programming and Scripting

Script Automation

Hi Gurus, I have a clearcase script that i use to check in a single file at time on my clearcase server. the script is as follows setmyview settask 75098_MSI_TRILOGY_EIM cd /vobs/Trilogy_R12/custom/msieim/12.0.0/sql/ cleartool co -nc . ct mkelem -nc Filename_1.sql cp... (3 Replies)
Discussion started by: r_t_1601
3 Replies

4. Shell Programming and Scripting

Script For Folder Management Automation

Let me start off by saying I am not a linux guy nor do I script much (I modify scripts a bit) but I am looking for a code to help automate file management on usb sticks with clonezilla images. I'm looking for a script to recognize folder names and allow a max of 2 folders with the same text in... (6 Replies)
Discussion started by: traustic
6 Replies

5. Shell Programming and Scripting

sftp automation script not working

Hi all , can any one tell me how to code SFTP automation script ? I searched lots of forums but i didn't get any useful information:( I don't want auto Login script > like if u run the script it should automatically login into specific account and etc.. Just i want the following things... (4 Replies)
Discussion started by: sravan008
4 Replies

6. Shell Programming and Scripting

Help with Shell Script automation

can someone look into this one please... I am struck at this point. I do not know what logic to be followed here. I can go ahead with my work only, if this step is done. Please Help. I have a process X in a shell script. Once the process X is done, it generates a log file. Process X is basically... (1 Reply)
Discussion started by: ss3944
1 Replies

7. Shell Programming and Scripting

FTP automation script

Hi, I have got a requirement like this. a parameterized function custFtp which will take 5 i/ps and will do the following tasks. p1) server name p2) username p3) password p4) path name of the server where the file resides p5) file name pattern the function will work like this. ... (1 Reply)
Discussion started by: ani_datta
1 Replies

8. Filesystems, Disks and Memory

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

9. UNIX Desktop Questions & Answers

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

10. UNIX for Dummies Questions & Answers

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies
Login or Register to Ask a Question