Script No .
Definition:
Create a file called student containing roll-no, name and marks.
a. Display the contents of the file sorted by marks in descendingorder
b. Display the names of students in alphabetical order ignoring thecase.
c. Display students according to their rollnos.
d. Sort file according to the second field and save it to file‘names’.
e. Display the list of students who scored between 70 and80.
Script:
clear
echo 1: Display the content in descending order of marks
echo 2: display the name of the students in alphabetical order ignoring the case
echo 3: Display according to rollno
echo 4: Sort the file as per second field and save to file "names"
echo 5: Display the student who scored between 70 to 80
echo enter your choice
read ch
case $ch in
1) echo sort the data based on marks descending order
sort -n -r -t " " --k3 data45;;
2) echo display the students name in ascending order ignoring case
sort -i -t " " -k2 data45;;
3) echo sort acording to a roll number
sort -n data45;;
4) echo sort file as per name and save it to a new file called names
sort -t " " -k2 data45 >names;;
5) echo display students who percentage is between 70 and 80
t=`cat data45 | wc -l`
i=1
while [ $i -le $t ]
do
l=`cat data45 | head -$i | tail -1`
val=`echo $l | cut -d " " -f3`
i=1
OR
echo "enter the filename"
read fn
#cheking for file
if [ -f "$fn" ]
then
echo "1. Display the contents of the file sorted by marks in descending order"
echo "2. Display the names of the students in alphabetical order ignoring rhe case."
echo "3. Display the students according to their roll nos."
echo "4. Sort file according to the second field and saave it to file 'names'."
echo "[Link] the list of students who scored between 70 and 80"
echo "Enter your choice"
read ch
case $ch in
1) sort -k5 -r $fn;;
2) sort -k3 -i $fn;;
3) sort $fn;;
4) sort -k3 $fn>names;;
5) awk '{ if($3 >= 70 && $3 <= 80) print }'$fn;;
*) echo "Invalid Choice";;
esac
else
echo "Files does not exists : $fn"
fi