Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This should do the job and is should be simple to follow <em>(requires GNU awk)</em>:</p> <pre><code>FILENAME=="file1"{ # When reading file1 SID[$1] = $2 # Student ID/Name key value pair } FILENAME=="file2"{ # When reading file2 ID = $1 # Store the course ID sub(/[A-Z]+[0-9]+\s+/,"",$0) # Remove the course ID from the line CID[ID] = $0 # Coursename/ID key value pair } FILENAME=="file3"{ # When reading file3 GRADE[$1][$2] = $3 # (StudentID/CourseID)/Grade key value pair } END { # After all the files have been read n = asorti(SID,SSID) # Sort by student ID for (i=1;i&lt;=n;i++) { # For all the students s = SSID[i] # Store the current student ID print "Roll No:",s # Print student ID print "Name:",SID[s] # Print student name for (c in CID) # For all the courses if (GRADE[s][c]) # If the student has a grade for the course printf "CourseID: %s, CourseName %s, grade:%s\n", c, CID[c], GRADE[s][c] } } </code></pre> <p>Running on your input:</p> <pre><code>$ awk -f report.awk file1 file2 file3 Roll No: 1 Name: Student1 CourseID: BM13, CourseName Linux, grade:AB CourseID: MT15, CourseName Business Management, grade:BB CourseID: CS11, CourseName Discrete Mathematics, grade:AB CourseID: CS12, CourseName Business Communication, grade:BC Roll No: 2 Name: Student2 CourseID: BM13, CourseName Linux, grade:AB CourseID: MT15, CourseName Business Management, grade:AB CourseID: CS11, CourseName Discrete Mathematics, grade:AA CourseID: CS12, CourseName Business Communication, grade:AA Roll No: 3 Name: Student3 Roll No: 4 Name: Student4 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload