counting in unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers counting in unix
# 1  
Old 04-15-2009
counting in unix

my script:
count=0while test $count -lt 10do#do something for 0,1,2...9 count=$(($count+1))doneIt doesnt work. Can anyone tell me what im doing wrong?? thanks
# 2  
Old 04-15-2009
Please use indentation in your code and use code tags.
To do this, select the code with the mouse and click on # above the edit box.

Regards
# 3  
Old 04-15-2009
Code:
count=0
while test $count -lt 10
do
#do something for 0,1,2...9
  count=$(($count+1))
done


Last edited by Franklin52; 04-15-2009 at 02:27 PM.. Reason: Code tags
# 4  
Old 04-15-2009
Dont use $count. use only count like
count=$((count + 1)).
# 5  
Old 04-15-2009
Hi,
What is it that doesn't work? What did You expect it to do?
If i do
Code:
count=0
while test $count -lt 10
do
echo $count
count=$(($count+1))
done

i get
Code:
0
1
2
3

and so on. It works. The comment "#do something for 0,1,2...9" doesn't actually do anything so what You have is loop that start and finishes...

/Lakris

EDIT: Sorry forgot to mention that I use bash but I tried in ksh as well and it works the same.
# 6  
Old 04-15-2009
i get a blank screen
# 7  
Old 04-15-2009
Ok, so I ask again, what did You expect it to do?
It is a loop that counts from 0 to 9 but it doesn't actually do anything, You haven't done any visible actions based on, for example, the count. So it shouldn't show anything.
Have You tried my modified code? Maybe that can give You an idea?

/Lakris
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting files without ls or wc

i need to write a shell script to "count the number of files in the current directory but without using either ls or wc command"..... please help! (1 Reply)
Discussion started by: lexicon
1 Replies

2. 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

3. Shell Programming and Scripting

Alphabet counting

I have a text file in the following format CCCCCGCCCCCCCCCCcCCCCCCCCCCCCCCC AAAATAAAAAAAAAAAaAAAAAAAAAAAAAAA TGTTTTTTTTTTTTGGtTTTTTTTTTTTTTTT TTTT-TTTTTTTTTCTtTTTTTTTTTTTTTTT Each row/line will have 32 letters and each line will only have multiple occurrences of 2 letters out of a pool... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

4. 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

5. Shell Programming and Scripting

Counting words

Hi Is there a way to count the no. of words in all files in directory. All are text files.I use wc -w but somehow i am not getting the rite answer. Is there an alternative. Thanks in advance (9 Replies)
Discussion started by: kinny
9 Replies

6. Shell Programming and Scripting

Counting similar lines from file UNIX

I have a file which contains data as below: nbk1j7o pageName=/jsp/RMBS/RMBSHome.jsf nbk1j7o pageName=/jsp/RMBS/RMBSHome.jsf nbk1j7o pageName=/jsp/RMBS/RMBSHome.jsf nbk1j7o pageName=/jsp/RMBS/RMBSHome.jsf nbk1j7o pageName=/jsp/common/index.jsf nbk1j7o pageName=/jsp/common/index.jsf nbk1wqe... (6 Replies)
Discussion started by: mohsin.quazi
6 Replies

7. 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

8. Shell Programming and Scripting

Counting with Awk

I need "awk solution" for simple counting! File looks like: STUDENT GRADE student1 A student2 A student3 B student4 A student5 B Desired Output: GRADE No.of Students A 3 B 2 Thanks for awking! (4 Replies)
Discussion started by: saint2006
4 Replies

9. IP Networking

Unix Scripts & Counting TCP Connections

Here's a question I received on a test recently. I'm new to Linux/Unix so if this is easy, don't kill me. What scripting or tools could you use to count and sort the number of connections from each internal host? I'd appreciate any feedback and resources. "The Cisco PIX firewall provides... (5 Replies)
Discussion started by: daveohr
5 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