5
B 2 Batch Practical-7 PRACTICAL – 7 Operating System Page | 54

Practical 7 Ans Os

Embed Size (px)

DESCRIPTION

os lab

Citation preview

Page 1: Practical 7 Ans Os

B2 Batch Practical-7

PRACTICAL – 7

1. Write a shell script to check whether the entered string is in title case or not.

Operating System Page | 54

Page 2: Practical 7 Ans Os

B2 Batch Practical-7

CODE:echo Enter Stringread stf=0for i in `echo $st`do

u=`echo $i | cut -c 1 |grep -c [[:upper:]]`d=`echo $i | cut -c 1 |grep -c [[:digit:]]`if [ $u = 1 -o $d = 1 ]then

f=1continue

else echo string is not in titlecase exit

fidoneif [ $f = 1 ]then

echo String is in titlecasefi

OUTPUT:[it0623@linuxserv dp]$ sh p6_8.shenter the stringhelloString is not in title case$ sh p9_1.shenter the stringHELLOString is in title case

2. Write a shell script to check whether the scanned word is a uppercase word or not.

CODE:echo Enter the wordread wl=`echo $w | wc -c`len=`expr $l - 1`echo $w $l $leni=1c=0while [ $i -le $len ]do

u=`echo $w |cut -c $i|grep -c [[:upper:]]`i=`expr $i + 1`if [ $u = 1 ]

Operating System Page | 55

Page 3: Practical 7 Ans Os

B2 Batch Practical-7

thenc=`expr $c + 1` continue

else echo word is not in uppercase exit

fidoneif [ $c = $len ]then

echo word is in uppercasefi

OUTPUT:[it0623@linuxserv dp]$ sh p69.shenter the wordHelloWord is not an uppercase word$ sh p9_2.shenter the wordhelloWord is not an uppercase word$ sh p9_2.shenter the wordHELLOHELLO is Uppercase word

3. Write a shell script to count number of uppercase words in a string.

CODE:echo Enter Stringread stw=0for i in `echo $st`do

count=0l=`echo $i | wc -c`len=`expr $l - 1`k=1while [ $k -le $len ]do

u=`echo $i |cut -c $k|grep -c [[:upper:]]`if [ $u = 1 ]then

count=`expr $count + 1`fik=`expr $k + 1`

done

Operating System Page | 56

Page 4: Practical 7 Ans Os

B2 Batch Practical-7

if [ $count = $len ]then

w=`expr $w + 1`fi

doneecho no of upper case words are $w

OUTPUT:[it0623@linuxserv dp]$ sh p6_10.shsh p610.shenter the stringhelloNumber of Uppercase word are=0$ sh p9_3.shenter the stringHelloNumber of Uppercase word are=0$ sh p9_3.shenter the stringHELLONumber of Uppercase word are=1

Operating System Page | 57