LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-02-2011, 02:58 AM   #1
kpinto
LQ Newbie
 
Registered: Jun 2011
Posts: 3

Rep: Reputation: Disabled
Smile count how many number occurrences in series


hi all ;
i try to make a script in bash that u choose a number
for example 501 and another number like 1
and find how much the 1 number repeat in all numbers from 1 to 501
for example 11 -->1 repeat 2 times.

in 1 to 501 the number 1 repeat 200 times

THX
 
Old 06-02-2011, 03:16 AM   #2
arochester
Member
 
Registered: May 2006
Distribution: Debian
Posts: 615

Rep: Reputation: 98
This looks very hypothetical and like homework.

I cannot think of a reasonable, practical use for such an operation.

What have you written of the script so far and what result does it produce?
 
Old 06-02-2011, 04:00 AM   #3
kpinto
LQ Newbie
 
Registered: Jun 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
i am not a student but it's a question that my child receive in mat he answer on this question and i try to figure how to wrote a bash script.

i made this script to write all number from 1 to 501

#!/bin/bash
COUNTER=501
until [ $COUNTER -lt 1 ]; do
echo $COUNTER
let COUNTER-=1
done


and made this script to find the number 1
awk '/1/ { count++ } END { print count }' /debug/file.txt

but i receive 177 and i don't know how he can count digits in number.

thanks for you're answer.
 
Old 06-02-2011, 07:24 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,996

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187
Well I actually get 201 when going up to 501 ... havent checked by hand but the lower values test and work properly:
Code:
awk -vlast=501 -vsearch="1" 'BEGIN{for(i=1;i<=last;i++)n += split(i,_,search) - 1;print n}'
 
Old 06-02-2011, 08:22 AM   #5
kpinto
LQ Newbie
 
Registered: Jun 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
many thx

i will try to figure out what u did
it works properly
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to count occurrences of unique words in a file beeblequix Linux - General 8 06-05-2018 10:16 AM
Mapping with series from master file and calculate count saurabhmehan Linux - Newbie 1 09-08-2010 04:20 PM
the number of occurrences of the word in file hinetvenkat Linux - Software 1 02-20-2008 06:25 AM
how to count the number of occurrences of a process beeblequix Linux - General 3 09-18-2006 04:17 PM
help on finding the number that has max occurrences in a column [sql query] zeppelin Programming 6 06-15-2004 01:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration