Automatic counter script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Automatic counter script
# 15  
Old 05-11-2012
Please post your original input data.
# 16  
Old 05-11-2012
I am using a modified version of the code you provided


Code:
awk 'N>=100000 { $2="Loc"; N=0 } 1; { N+=$1 }' filename

the original input data looks like this:

Code:
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  
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  
429	 Loc   		0.20935	0.64897




and the output data should look like this:





Code:
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.5597965	91.9804731
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                                 191.2945965	187.3045231
429	    Loc		0.20935	0.64897


Notice how the sum of the range of the the numbers in between Loc's in col3 and col4 are printed in col 5 and col6

Last edited by verse123; 05-11-2012 at 03:50 PM..
# 17  
Old 05-11-2012
Is the data tab-separated?
# 18  
Old 05-11-2012
sorry about the format, I wish I could just upload the file. and I can convert it into tab delimited but it currently is not
# 19  
Old 05-11-2012
You can upload the file actually. Look for 'manage attachments' when making a post.

You could describe what the file is, too, instead of what it isn't, reducing the number of questions needed.
# 20  
Old 05-11-2012
sorry about the formatting inconvenience. I have attached what the input looks like and what the output looks like.
# 21  
Old 05-11-2012
Your data is tab-separated.

This cannot be your original data, because you've already inserted all those 'loc'-s in it. Still working on it, but it'll mean you'll have two programs to run, not one...
 
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