Student Record Mini Project (Menu-Driven Shell Script)

This mini project stores student data in a file (students.txt) and provides options to:

1️⃣ Add Record
2️⃣ View All Records
3️⃣ Search Record
4️⃣ Delete Record
5️⃣ Update Record
6️⃣ Exit


🗂️ Data Format (students.txt)

RollNo|Name|Marks
101|Rahul|85
102|Amit|90

🖥️ Script: student_record.sh

#!/bin/bash

file="students.txt"

touch $file

while true
do
    echo "-----------------------------"
    echo "1. Add Student Record"
    echo "2. View All Records"
    echo "3. Search Student by Roll No"
    echo "4. Delete Student Record"
    echo "5. Update Student Marks"
    echo "6. Exit"
    echo "Enter your choice:"
    read choice

    case $choice in

    1)
        echo "Enter Roll No:"
        read roll
        echo "Enter Name:"
        read name
        echo "Enter Marks:"
        read marks
        echo "$roll|$name|$marks" >> $file
        echo "Record added successfully."
        ;;

    2)
        echo "Student Records:"
        cat $file
        ;;

    3)
        echo "Enter Roll No to search:"
        read roll
        grep "^$roll|" $file
        ;;

    4)
        echo "Enter Roll No to delete:"
        read roll
        grep -v "^$roll|" $file > temp.txt
        mv temp.txt $file
        echo "Record deleted successfully."
        ;;

    5)
        echo "Enter Roll No to update marks:"
        read roll
        echo "Enter new marks:"
        read newmarks
        grep -v "^$roll|" $file > temp.txt
        echo "$roll|UpdatedName|$newmarks" >> temp.txt
        mv temp.txt $file
        echo "Record updated successfully."
        ;;

    6)
        echo "Exiting program..."
        break
        ;;

    *)
        echo "Invalid choice!"
        ;;

    esac
done

✅ How to Run

chmod +x student_record.sh
./student_record.sh

🎯 Sample Output

1. Add Student Record
2. View All Records
3. Search Student by Roll No
4. Delete Student Record
5. Update Student Marks
6. Exit
Enter your choice: 1

🔥 Commands Used (Viva Important)

  • touch → create file
  • cat → display records
  • grep → search record
  • grep -v → delete record
  • mv → replace file
  • >> → append data

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *