OPA JULY 24 Unix 

Student details are stored in a file in the following format . Fields in the file are separated by comma(,).


Note: The roll number of the students is unique.
Roll,Name,Subject,Score


Write the Unix command to print the roll numbers of the students who has failed in only one subject. A student is considered as fail if the score is less than 60. One student might have multiple records in the file if the has scored for more than one subject.

In the output display only the roll numbers . In case no such students found there will not be any output.


Refer the example below for more clarity on input and output format.
The file name input will be provided as command line argument when the script containing your command will run.


You can use shell variables (e.g. $05152) whichever is applicable for your requirement to provide the command line argument.

Example:


If the input file has following data:


Roll,Name,Subject,Score

101,Adam,CsC,30

102,Juhi,Math,78

101,Adam,Math,90

103,Adam,Math,50

101,Adam,CHM,50

102,Juhi,CsC,50


Expected Output:
102 103
Here the above output related students have failed only in one subject

Solutions:

 

 

 

 

 

 

Try in online compiler -> click here

awk 'BEGIN{FS=",";}{if($4<60){a[$1]+=1;}}END{for(i in a){if(a[i]==1){print(i)}}}'

 

©2018 by The real one. Proudly created with Wix.com