postheadericon Write a script for generating a mark sheet after reading data from a file. File contains student roll no, name , marks of three subjects.


studInfo.txt

hitesh,30,70,80
mitesh,30,80,40
jitesh,30,35,40
ritesh,100,100,100

Ex13.sh

clear
len=`cat studInfo.txt | wc -l`
i=1
echo "\n\n\t\t\t [   STUDENT MARKSHEET  ]\n"
echo "__________________________________________________________________________"
echo "#\t NAME \t \t \t TOTAL \t \t PERCENTAGE \t GRADE "
echo "__________________________________________________________________________"

while [ $i -le $len ]
do
     record=`head -n $i studInfo.txt | tail -n 1`
     total=0
     j=2
     isFail=0
     while [ $j -le 4 ]
     do
        marks=`echo $record | cut -d "," -f $j`
        if [ $marks -lt 40 ]
        then
            isFail=1
        fi
        total=`expr $marks + $total`  
            j=`expr $j + 1`      
     done
     name=`echo $record | cut -d "," -f 1`
     per=`expr $total / 3`

    if [ $isFail = 0 ]
    then
        if [ $per -ge 85 ] && [ $per -le 100 ]
         then
            grade="AA"
         elif [ $per -ge 75 ] && [ $per -le 84 ]
         then
            grade="AB"
         elif [ $per -ge 65 ] && [ $per -le 74 ]
         then
            grade="BB"
         elif [ $per -ge 55 ] && [ $per -le 64 ]
         then
            grade="BC"
         elif [ $per -ge 45 ] && [ $per -le 54 ]
        then
            grade="CC"
         else
            grade="FF"
         fi
     else
           grade="FF"
        
     fi

     echo "$i \t $name \t \t $total \t \t $per % \t \t $grade"
     i=`expr $i + 1`
done
echo "__________________________________________________________________________\n"

postheadericon sort files in unix by size


#Write a script to display the directory in the descending order of the size of each file.

ls -lS

#Write a script to display the directory in the Ascending order of the size of each file.

ls -lSr

#option  [ -l  ] is use for log listing
#option  [ -S ] to sort  by size
#option  [ -r ] use for revers ordering

postheadericon date command in unix


#Write a script to display the date, time and a welcome message (like Good Morning etc.). The time should be displayed with “a.m.” or “p.m.” and not in 24 hours notation.

currentHour=`date +%H`

currentTime=`date +"%I : %M : %S %p"`

if [ $currentHour -lt 12 ]
then
    msg="Good Morning"

elif [ $currentHour -ge 12 ]  &&  [ $currentHour -lt 16 ]
then
    msg="Good Afternoon"

elif [ $currentHour -ge 16 ]  &&  [ $currentHour -lt 21 ]
then
    msg="Good Evening"
else
    msg="Good Night"
fi
#format of time  [ HH : MM : SS : AM/PM]
echo "$msg ,\nCurrent Time is  $currentTime"

postheadericon Write a script to display the name of all executable files in the given directory.



clear
echo "Enter Directory Name : "
read dir

ls $dir>fileList.txt
count=0

if [ -d $dir ]
then
     for fileName in `cat fileList.txt`
     do
        if [ -x $dir/$fileName ]
        then
           echo "$fileName"
           count=`expr $count + 1`
        fi
     done
fi
echo "Total Executable Files : $count"
rm fileList.txt

postheadericon Write a script to display the name of those files (in the given directory) which are having multiple links.

 

clear
echo "Enter Directory : "
read dir

# check inputed name is directory or not
if [ ! -d $dir ]
then
echo "DIRECTORY [ $dir1 ] NOT EXIST"
exit 1
fi

#count total number of lines
len=`ls -l $dir | wc -l`
i=2

echo "File With Multiple Link are "

while [ $i -le $len ]
do
# select one by one record from entire group of records
record=`ls -l $dir | head -n $i | tail -n 1`

#grab the file name
f=`echo $record | cut -d " " -f 8`

#grab the total hard link to that file
link=`echo $record | cut -d " " -f 2`

#if multiple links then print file with link
if [ $link -gt 1 ]
then
echo "$f = $link"
fi

#increment the counter
i=`expr $i + 1`
done

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.