Counting under some condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting under some condition
# 1  
Old 02-04-2010
Counting under some condition

I want to develop a shell script but with a bit complicated conditions. I have a file contains a data. The data change every 5 mins.
If the file having data repeated 3 times then add 5 to the counter. By using crontab I will let the script check the file again and if the same 3 data are exist then add another 5 till it reach to 40. Another condition if one of the check dose not have the same repeatative data then the counter should be reset. We may have more than one repetative data then another counter should be start.
ex. file name is ( Main ) and the data is as follow:
NBB001
NBB001
NBB001
TTF033
and because the data changes we might have another data like

NBB001
BFG123

and another ex.
NBB001
NBB001
NBB001
TTF033
TTF033
TTF033

what I want basicly is to have counter running every time i check the file and if it reach to 40 then do some command and if reach 60 do another command. As above if data not continusly available the ounter should be reset and if there is more than one data repeated 3 times then another counter should work.

Appreciate your help
# 2  
Old 02-04-2010
I dont think I understand exactly what you are asking for. Does the data have to occur one after other or can there be other information between two similar lines?
Try "grep -c <data> <Filename>" if that helps
# 3  
Old 02-05-2010
yes the grep will count how many times similar data repeated but I want if its repeated 3 times then count 5 and then atfer 5 mins by using crontab I will re-access the file and check if it has repeatative data occur or not till it reach counting 40.

example

time 12:00 the file (main) has a data as follow:

BBB111
BBB111
BBB111
TNG877
NNT555
SDF990
SDF990
SDF990

The script should count 5 for BBB111 and store it and count 5 for SDF990 and store it

time 12:05 the file main has a data as follow:
BBB111
BBB111
BBB111
TNG877
NNT555

The script will add another 5 for BBB111 which will 10 adn it will reset the counter for SDF990 to zero.
if BBB111 continue appear into file till count reach 40 then do some command.

thanx

---------- Post updated 02-05-10 at 09:31 AM ---------- Previous update was 02-04-10 at 01:50 PM ----------

Any idea...
Appreciate your assist
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

2. Shell Programming and Scripting

Counting the records based on condition

Hi Unix team, I have a file with 30 columns with tab delimited. I need to count the records based on column 18 & 21 data. So I cut the data from the file using awk -F"\t" '{print $18,$21}' foo.txt Following is the output: USED SEDAN USED SUV NEW SUV USED Truck USED Truck USED... (6 Replies)
Discussion started by: karumudi7
6 Replies

3. Shell Programming and Scripting

[AWK script]Counting the character in record and print them in condition

.......... (1 Reply)
Discussion started by: Antonlee
1 Replies

4. UNIX for Dummies Questions & Answers

counting?

Hi all, I promise this is my very last dumb question.. but how to you count how many unique names you have. My dataset is: >Bac1 afdsgrr >Bac4 egege >Bac8 dgrjh >Bac1 afdsgrr >Bac1 afdsgrr >Bac8 dgrjh What i want to know is that how many unique names there is, so the output would... (3 Replies)
Discussion started by: Iifa
3 Replies

5. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

6. UNIX for Dummies Questions & Answers

Counting # of lines

Counting number of lines: sp I am trying to figure out a script to count the number of text files in cywig and have it give me a number (as the answer) any help would be appreciated. I am new here, so be gentle :D (3 Replies)
Discussion started by: unicksjp
3 Replies

7. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

8. Shell Programming and Scripting

Counting

Hi, The following output shows how many pmon process are started by users named : oracle or yoavb $ ps -ef |grep pmon |grep -v grep |grep -v ipmon oracle 11268 1 0 Sep 2 ? 36:00 ora_pmon_qerp oracle 17496 1 0 Oct 11 ? 8:58 ora_pmon_bcv oracle 15081 1 0 ... (5 Replies)
Discussion started by: yoavbe
5 Replies

9. Shell Programming and Scripting

Counting

Hi, I want to count how many rows are in a file for a specific column. eg. K NM K NM K NM K JK K NM K JK K NM so the file is tab-delimited. I want to count how many rows are in column 2 and how many NMs there are. I used awk awk '{OFS="\t"}; {count++} {print i,... (3 Replies)
Discussion started by: phil_heath
3 Replies

10. UNIX for Dummies Questions & Answers

Counting and sort

Hello friends, I have the following data: abc-xyz abc = 0-999 xyz = 0-999 and there are 10000 lines or more: Example of data file: 123000 123001 123004 123005 123004 123004 123008 123008 (4 Replies)
Discussion started by: bobo
4 Replies
Login or Register to Ask a Question