Professional Documents
Culture Documents
PAGE
S.NO DATE TITLE SIGN
NO
1 SUM OF DIGITS
2 REVERSE OF A NUMBER
7 STRING MANIPULATION
9 USER LOGGED IN
DATE :
AIM:
To write a Linux program to find out the Sum of the digits for the given
number.
ALGORITHM:
CODING:
echo ‘ ------------------------ ‘
read n
s=0
while [ $n –gt 0 ]
do
r=$((n % 10))
s=$((s + r))
n=$((n / 10))
done
OUTPUT:
123456789
RESULT:
Thus the program has been executed successfully and the output is shown.
EX.NO : 2 REVERSE THE NUMBER
DATE :
AIM:
To Write a Linux program to find out the Reverse the digits for the given
number.
ALGORITHM:
CODING:
echo ‘ ----------------------------- ‘
read n
s=0
while [ $n –gt 0 ]
do
r=$((n % 10))
n=$((n / 10))
s=$((s * 10 + $r))
done
OUTPUT:
vpmm@vpmm : ~$ sh reverse
123456789
RESULT:
Thus the program has been executed successfully and the output is shown.
EX.NO: 3 PERFORM BASIC ARITHMETIC OPERATION USING CASE
DATE :
AIM:
ALGORITHM:
CODING:
echo ‘ --------------------------------------------- ‘
read a
read b
echo 1.Addition 2.Subtraction 3.Multiplication 4.Division 5.Modules
read c
case $c in
esac
OUTPUT:
vpmm@vpmm: ~ sh arithmetic
Enter ur choice: 3
Multiplication: 15
RESULT:
Thus the program has been executed successfully and the output is shown
EX.NO :4 DISPLAY MUTIPLICTION TABLE
DATE :
AIM:
ALGORITHM:
CODING:
echo ‘ ----------------- ‘
read tn
read n
i=1
while [$i –le $n ]
do
k=$((i *tn))
echo “ $i * $tn = $k “
i=$((i+1))
done
OUTPUT:
vpmm@vpmm:~ sh multab
MULTIPLICATION TABLE
---------------------------------------
Enter Table Number: 5
Enter How Many Rows U Need: 5
1*5=5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 =25
RESULT:
Thus the program has been executed successfully and the output is
shown.
EX.NO:5 CHECK WHETHER A NUMBER IS PRIME OR NOT USING
WHILE
DATE:
AIM:
To Write a Linux program to check whether the given number is prime or not
using while.
ALGORITHM:
echo ‘ ----------------------------------------------------------------------------------‘
read n
i=2
f=0
do
then
f=1
fi
i=`expr $i + 1`
done
if test $f –eq 0
then
else
fi
OUTPUT:
RESULT:
Thus the program has been executed successfully and the output is shown.
EX.NO: 6 CONVERT LOWERCASE TO UPPERRCASE USING TR
DATE :
AIM:
ALGORITHM:
CODING
getFile()
read upper
if [ ! –f $upper ]; then
Exit 1
fi
}
clear
echo “3.exit “
read Ch
case “$Ch” in
1)
getFile
echo “ ------------------------------------------------ “
;;
2)
getFile
echo “ --------------------------------------------- “
;;
*)echo “Exiting…”
exit
;;
esac
OUTPUT:
1.Uppercase to Lowercase
2.Lowercase to Uppercase
3.Exit
Existing…
RESULT:
Thus the program has been executed successfully and the output is shown.
EX.NO:7 PERFORM STRING MANIPULATION
DATE:
AIM:
ALGORITHM:
CODING:
echo ‘ --------------------- ‘
read s
len= `echo $s | wc –c `
do
temp=`echo $s | cut –c $ln`
done
OUTPUT:
vpmm@vpmm:~ sh manip
STRING MANIPULATION
-----------------------------------
Enter the String :
Anjanaria
RESULT:
Thus the program has been executed successfully and the output is shown.
EX.NO:8 PATTERN MATCHING USING GREP COMMAND
DATE:
AIM:
ALGORITHM:
Get the input value of pattern and file name from the keyboard.
the screen.
echo ‘ --------------------- ‘
read pn
read names
echo
cat $names
names
anu
koppu
malli
muni
shobi
suji
OUTPUT:
vpmm@vpmm:~$ sh pattern
PATTERN MATCHING
-------------------------------
Enter the pattern to be Search: Malli
Enter the File Name: Name
Anu
Koppu
Malli
Muni
Shobi
suji
RESULT:
Thus the program has been executed successfully and the output is shown.
EX.NO:9 FIND THE NUMBER OF USER WHO HAVE LOGGED IN
DATE:
AIM:
To write a Linux program to find the number of user who have logged in.
ALGORITHM:
Get the input value of the number of user entered through the
We can show which users the first one to enter into the system.
CODING:
echo ‘ --------- ‘
who | wc -1
who | head -1
OUTPUT:
vpmm@vpmm:~$ sh login
LODIN USER
------------------
The Number of user Login are: 2
RESULT:
Thus the program has been executed successfully and the output is shown.
EX.NO:10 CHECK FOR PALINDROME
DATE :
AIM:
ALGORITHM:
echo ‘ ----------------------------------------------------------------- ‘
read n
x=$n
s=0
do
r=$((n%10))
s=$((s\*10+r))
n=$(($n/10))
done
if [ $s –eq $x ]
then
else
fi
OUTPUT:
vpmm@vpmm:~$ sh palind
151
vpmm@vpmm:~$ sh palind
RESULT:
Thus the program has been executed successfully and the output is shown.
EX.NO:11 MENU DRIVEN IMPLEMENTATION
DATE :
AIM:
ALGORITHM:
keyboard.
Enter the choice one by one from the keyboard by using case.
We can use the data ,ps ,who and Is -1 command for getting the
echo ‘ ----------------------------- ‘
echo ‘ 1.Today DATA 2.Processing the system 3.User of the System 4.List of the
Files ‘
read c
case $c in
1)data;
2)ps;;
3)who;;
4)Is – 1;;
esac
OUTPUT:
vpmm@vpmm:~$ sh driven
MENU IMPLEMENTATION
--------------------------------------
1. Today DATE 2.Processing the System 3.Users of the system
4. List of Files
Enter Ur choice:
vpmm@vpmm:~$ sh driven
MENU IMPLEMENTATION
----------------------------------------
1. Today date 2.Processing the system 3.Users of the system 4.List of Files
Enter Ur choice:
vpmm@vpmm:~$ sh driven
MENU IMPLEMENTATION
--------------------------------------
1. Today date 2.Processing the System 3.Users of the System 4.List of Files
Enter Ur choice:
Enter Ur choice:
rajeshkumar@rajeshkumar:~$
RESULT:
Thus the program has been executed successfully and the output is shown.
AIM:
To write a Linux program to get mark details of a student and display total
and grade.
ALGORITHM:
CODING:
echo ‘ ----------------------- ‘
read name
read rno
echo ‘ Mark 1 : ‘
read m1
echo ‘ Mark 2 : ‘
read m2
echo ‘ Mark 3 : ‘
read m3
echo ‘ Mark 4 : ‘
read m4
echo ‘ Mark 5 : ‘
read m5
avg=$(expr $tot / 5)
echo ‘ --------------------- ‘
echo”Mark1 :$m1”
echo”Mark2 :$m2”
echo”Mark3 :$m3”
echo”Mark4 :$m4”
echo”Mark5 :$m5”
echo”Total :$tot”
echo”Average :$avg”
if [ $m1 –ge 35 ] && [ $m2 –ge 35 ] && [ $m3 –ge 35 ] && [ $m4 –ge 35 ] && [
$m5 –ge 35 ]
then
if [ $avg –ge 90 ]
then
then
then
then
then
then
fi
else
fi
OUTPUT:
vpmm@vpmm:~$ sh mark
Mark1 : 65
Mark2 : 75
Mark3 : 85
Mark4 : 76
Mark5 : 87
Total : 388
Average : 77
Result : pass
Grade :B
RESULT:
Thus the program has been executed successfully and the output is shown.
AIM:
ALGORITHM:
We can find out the consumed unit and its total price by using the
formula.
CODING:
echo ‘ ---------------------- ‘
read name
read cmr
read lmr
if [ $unit –eq 0 ]
then
charge=40
then
charge=$(expr $unit \* 1)
then
then
then
fi
echo”Unit :$unit”
OUTPUT:
Electricity Bill
-------------------
Consumer Name : Laxmi
Unit : 333
Charge : 766
RESULT:
Thus the program has been executed successfully and the output is shown.
AIM:
ALGORITHM:
If the condition has been satisfied then print attributes was set for file
CODING
echo ‘ -------------------------------------- ‘
read fn
if chmod +x $fn
then
echo ‘ Successfully Run Mode Attributes was set for files ‘
else
fi
bye
OUTPUT:
RESULT:
Thus the program was has been executed successfully and the output is
shown.
AIM:
ALGORITHM:
Get the two input file names one by one from the keyboard.
If the condition has been satisfied then print both files are same else
CODING:
echo ‘ ------------------------------- ‘
read f1
then
else
fi
hai
bye
OUTPUT:
vpmm@vpmm :~ $ sh compare
RESULT:
Thus the program has been executed successfully and the output is shown.
AIM:
ALGORITHM:
CODING:
echo ‘ COPY AND RENAME A FILE ‘
echo ‘ --------------------------------- ‘
read f1
read f2
cp $f1 $f2
ls
read f3
mv $f2 $f3
ls
OUTPUT:
vpmm@vpmm- thinkpad-R61:~$ sh cfrf
Cfrf
raj
File copied
rya
File Renamed
RESULT:
Thus the program has been executed successfully and the output is shown
AIM:
ALGORITHM:
CODING:
echo ‘ --------------------------------------------------------- ‘
read fname
if [ -d $fname ]
then
echo ‘ It is a Directory ‘
else
fi
OUTPUT:
rajeshkumar@rajeshkumar :~ $ sh direct
--------------------------------------------------------------------------
It is not a Directory
RESULT:
Thus the program has been executed successfully and the output is shown.
AIM:
To write a Linux program to read 5 names from a file and sort in ascending
and descending order.
ALGORITHM:
We can create another one file that contains 10 names in any order.
We can use the sort and cat command to show the desired results on
CODING:
echo ‘ ASCENDING OREDR & DESCENDING ORDER USING 5 NAMES ‘
echo ‘ -------------------------------------------------------- ‘
read name
cat name_asce
cat name_desc
names
anu
koppu
malli
muni
shobi
OUTPUT:
rajeshkumar@rajeshkumar : ~ $ sh ascen
---------------------------------------------------------------------------------------
Anu
Koppu
Malli
Muni
Shobi
Shobi
Muni
Malli
Koppu
anu
RESULT:
Thus the program has been executed successfully and output shown.
AIM:
ALGORITHM:
If both are equal, the print given number is Adam else given number is
not Adam.
echo ‘ ------------------------------------------- ‘
read num
rev=0
do
done
rev 1=0
do
then
else
fi
OUTPUT:
ADAM NUMBER
_________________
Enter the Number:13
RESULT:
DATE:
AIM:
To write a Linux program to print current data, user name and current
directory.
ALGORITHM:
condition.
If the condition has been satisfied then print directory is found else
echo’-----------------------------------------------------------------------‘
echo”hello $LOGNAME”
echo”current Directory’pwd’”
OUTPUT:
RESULT:
Thus the program has been executed successfully and the result is shown.