I am working on a ksh script whose scenario is as follows:
I have a text file for students' reports which contains details of students like:
Student_1
Name: ABC
Class:X
Head Teacher:SITA
Status: Pass
Student_1
Name: ABCE
Class:X
Head Teacher:SITA
Status: Pass
Student_2
Name:ABCD
Class:XI
Head Teacher:RYAN
Status: Fail
Student_50:
Name:MIKE
Class:X
Head Teacher:RYAN
Status:Fail
What I need to do is to
Find the number of students by counting the lines that start with
Student_N
;Count how many students passed and how many students failed using the
Status:
line.- Find the name of students whose name starts with A.
I tried numerous things including:
sed -n '/Student_i<< Status/,/Status/p' students_details.txt >> report_card.txt
sed '/^Student_i<< Status/,/)/Status/$/!d/Status/s/^Student_i<< Status (///Status/s/);$//' students_details.txt >> report_card.txt
sed '/^Student_i<< Status/,/)Status$/!d;s/^Student_i<< Status (//;s/);$//' students_details.txt >> report_card.txt
sed '/^pass/,/);$/!d;s/^pass (//;s/);$//' students_details.txt>> report_card.txt
My desired output files are:
For point 1:
Student_1 : 2 Student_2 : 1 Student_50: 1
For Point 2:
Pass: 2 Fail: 2
For Point 3:
Count of Students whose name starts with "A" : 3
awk
orperl
in 'paragraph mode' rather thansed
. FWIW I don't see the relevance of theksh
tag here since you seem to be looking for a solution using external text-processing tools rather than the shell itself.awk 'BEGIN{RS=""} END{print NR}'