Automatic counter script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Automatic counter script
# 22  
Old 05-11-2012
I cannot figure out what your 'sum of range' is. I can calculate the first value right ( 99.5598 91.7126 ), but get the second wrong (165.583 177.227).
# 23  
Old 05-11-2012
You are correct, actually. After double checking, the value you are getting is the correct one. It must have changed for me after all of the data editing due to format issues.
# 24  
Old 05-11-2012
Are you sure you can't post your original input data? Smilie Been fighting with it for an hour over the 'loc' being one line below where you really need it...
# 25  
Old 05-11-2012
Think I got it. No I don't.
# 26  
Old 05-11-2012
Code:
$ cat back1.awk

BEGIN { FS="\t"; OFS="\t"; U[1]=0; U[2]=0; }

{
        if($2)
        {
                print L, U[1], U[2];
                U[1]=0; U[2]=0;
        }
        else if(L)    print L;

        U[1]+=$5;       U[2]+=$6;

        L=$0
}

END { print L }

$ awk -f back1.awk data

263                             1.35611 1.45967
1220                            1.11776 1.04671
427                             1.05608 2.29163
29647                           14.1881 18.9483
29647                           17.4202 4.50283
29647                           7.26278 7.64333
1558                            7.04701 12.8815
2853                            21.2036 30.6511
165                             3.19675 2.47742
351                             0.635679 0.24632
700                             3.6203  1.47666
952                             0.0198475 0.0215731
242                             14.8425 0
28339                           6.59308 8.33343 99.5598 91.7126
28339   Loc                     1.02122 1.58249
28339                           1.88546 2.19513
28339                           1.6666  5.5956
697                             92.9737 88.2462
1162                            3.13779 3.28445
2672                            4.30055 4.86017
4758                            32.9386 33.9011
4758                            9.70837 11.4292
5054                            17.9509 26.1322 165.583 177.227
429     Loc                     0.20935 0.64897
333                             1.76175 0.557484
349                             4.83053 0.998285
588                             0.865869 0.190589
325                             4.5798  3.25348
3054                            12.6445 11.7729
189                             0       0
790                             3.54955 3.00091
1153                            0.143333 0.0746837
344                             19.094  14.4526
5603                            7.61506 11.3433
309                             33.3859 18.145
486                             5.18424 3.36967
715                             0.378199 0.0545272
1350                            10.7811 14.9226
30846                           4.81402 8.67348
30846                           10.8604 4.7313
30846                           10.4034 8.67701

$

# 27  
Old 05-11-2012
This is excellent, thank you for your patience.

---------- Post updated at 07:17 PM ---------- Previous update was at 07:10 PM ----------

Can you explain what is actually going on in this? And what is U[1] and 2
# 28  
Old 05-15-2012
U is an array I used, U[1] is the first total and U[2] is the second total. I could as easily just have used Y and Z.

It checks whether the second field (Loc) exists, and if so, puts the total in the last line before printing it.

It's always one line behind, handling the previous line, not the current one, which is why it needs to check and print in END as well.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Help with simple script with counter

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am to create a script that checks a file for specific attributes. Read, write, execute, if the file is empty,... (13 Replies)
Discussion started by: silencep77
13 Replies

2. Shell Programming and Scripting

How to use counter to run the script to limit number?

I want to run my shell script to the limit number.Suppose I know in advance that MAX=5 then I want that my script run 5 times only.Something like below$ vi testingMAX=5COMMAND="ssh -l stpuser VHLDVWSAD001 /projects/st/utils/deploy/deployall.sh >/dev/null 2>&1 &" ; sleep 20;count=0while... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

3. Shell Programming and Scripting

Incrementing the date depending on the Counter (parameter) passed to the script

Hello Everyone, I have been trying to complete a shell script where, I need to increment the date depending on the file (depending on the date) availability on the remote server. i.e. Basically, I will be passing a counter (like parameter 1 or 2 or 3 or 4). First I will check for the... (1 Reply)
Discussion started by: filter
1 Replies

4. Shell Programming and Scripting

How to display a counter in shell script?

Hi, I am writing a script which processes large number of files in a directory. I wanto display a counter which increment after processing each file. I am processing each file in a for loop. If I echo a variable with its value increasing with each file, I will get around 5000 lines as output.... (10 Replies)
Discussion started by: jaiseaugustine
10 Replies

5. Shell Programming and Scripting

Reset the counter in shell script

I am executing the following script using 'awk -f process.awk out' where 'out' is the input file which consists of 5000 sequences. Each time it takes one sequence, run the below program by creating a directory, run the mfold command within that directory, running another shell script 'final5' and... (2 Replies)
Discussion started by: kswapnadevi
2 Replies

6. Shell Programming and Scripting

cant get a counter to work in bash scipt, this is calling expect script

I have looked high and low, tryed lots of diffrent things but cant get a simple counter to work right. what i need is to increase a count ever time it finishes the test, pass or fail. example TEST PASS 1, NEXT TEST PASS 2, I curently have set foo o while {$foo <=5} { incr foo puts... (1 Reply)
Discussion started by: melvin
1 Replies

7. UNIX for Advanced & Expert Users

Automatic script

Hi, is it possible to automatically run a script (bash) when an event occurs? I mean, let's say that I (or one of my users) plug in a flash memory (USB) ... is it possible to run a script every time I do this action (let's say to log user, date and other infos on a file)? Thanks! Bye... (5 Replies)
Discussion started by: TShirt
5 Replies

8. Shell Programming and Scripting

Accumulate counter in script

Hi, I'm new to unix and have a problem? I'm writing a basic script in ksh and it is a basic quiz with 5 questions. I need to be able to accumulate the correct answers at the end and echo out the total correct answers, I cannot work it out? Please see script so far. If anyone can help that will... (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

9. Shell Programming and Scripting

Counter Script..help please

I have generated a script that will email a list of people if a certain PID is not running, using "mailx". I have the script running every 5 minutes as a cron job. I want the script to stop sending an email, if the email has been sent 5 times (meaning PID is dead). I want this so that my... (3 Replies)
Discussion started by: Sunguy222
3 Replies

10. UNIX for Dummies Questions & Answers

Error in Script (counter)

Hello: Executing following script i'm getting error: 1=1+1: 0403-058 Assignment requires an lvalue. It's not assuming the counter but i don't know why. Some hint? Thank you very much in advance. #!/bin/ksh <path>/tiempos.txt num_exe=1 TIEMPOS=<path>/tiempos.txt while ] do (2 Replies)
Discussion started by: Felix2511
2 Replies
Login or Register to Ask a Question