write shell script to count occurence of a perticular digit in inputted number.


#!/bin/bash
#shell script to count occurence of a perticular digit in inputted number.

echo -n "enter any number:-"
read number
echo -n "which digit number do u want to count:-"
read digit
len=`echo -n $number |wc -c`
echo "the length of number is:-$len"
count=0
while test $len -gt 0
do
flag=`echo -n $number |cut -c $len`
if test $flag -eq $digit
then
count=`expr $count + 1`
fi
len=`expr $len - 1`
done

echo "|$digit| occured |$count| times in number ($number)"

1 comments:

Hey,


Gratitude for putting up this prolific article! You truly make everything a cake walk. Genuinely good stuff, saving time and energy.
I'm new to python and trying to make a basic tree, I have made this code to draw the triangles on top of each other but I am unable to work out how to make them larger as they go down. Can any one help?
Python Code: (Double-click to select all)
1
2
3
4
5
6
7
8
9
10
11
12
13 number_of_shapes = 3
for shape in range(1, number_of_shapes + 1):
# Draw a Triangle
for sides in range(1, 4):
forward(60)
left(120)
# Move forward to start position of next triangle
penup()
right(120)
forward(60)
left(120)
forward(30)
pendown()


Very useful article, if I run into challenges along the way, I will share them here.


Shukran,


EmoticonEmoticon