Automatic counter script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Automatic counter script
# 8  
Old 05-06-2012
The 1 is an implied 'print'. That's the spot, right after an outer code block, where you can put an expression for when to print the line. Any expression will do. A 1 is always true, causing the line to always be printed.
This User Gave Thanks to Corona688 For This Post:
# 9  
Old 05-06-2012
Thank you,

is there a way to bypass the fact that it must end up on an even 10?
# 10  
Old 05-06-2012
Yes, try >=.
# 11  
Old 05-10-2012
What if one wanted to expand on this code with the file below, for example:

Input file:

Code:
Col1 Col2   Col3           Col4                            
8              14.8425      0
2	        6.59308     8.33343
1	10     1.02122     1.58249         	
1              1.88546     2.19513
1	        1.6666       5.5956
1	    	92.9737     88.2462
1               3.13779    3.28445
1               4.30055    4.86017
1               32.9386    33.9011
1                9.70837   11.4292
2               17.9509    26.1322
23	10  	0.20935    0.64897

In this case, how can I add up the values in col 3 and print the total in col5 and add the values of col4 and print in col6 if a 10 is found. So, in the example below, Col5 prints 165.58319 because the summation of the values of col3 equal that amount (from where the first 10 is written in col2 and ending in the line before the second 10 is found), and so on.


output file:


Code:
Col1 Col2   Col3           Col4          col5               col6                        
8              14.8425      0
2	        6.59308     8.33343
1	10     1.02122     1.58249    165.58319        177.22654 
1              1.88546     2.19513
1	        1.6666       5.5956
1	    	92.9737     88.2462
1               3.13779    3.28445
1               4.30055    4.86017
1               32.9386    33.9011
1                9.70837   11.4292
2               17.9509    26.1322
23	10  	0.20935    0.64897     131.101001	    104.8667889


Last edited by verse123; 05-10-2012 at 02:19 PM..
# 12  
Old 05-10-2012
Post in code tags instead of quote tags so we can tell what your file really looks like.
# 13  
Old 05-10-2012
You could 'cheat' by putting two columns in one. $1=$1" " N or something like.
# 14  
Old 05-11-2012
the code tags worked

---------- Post updated 05-11-12 at 10:39 AM ---------- Previous update was 05-10-12 at 12:20 PM ----------

I do not understand what you mean by the code you wrote above. I tried to add it but I it does not sum up the values found in col3 between two col 2 "10" signals
This User Gave Thanks to verse123 For This Post:
 
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

Featured Tech Videos