You are on page 1of 2

Contents of intput file: studentsData

StudentNo|Name|Standard|SchoolName|MathematicsScore|ScienceScore
1|Latha|Third|Vikas|90|91
2|Neethu|Second|Meridian|92|94
3|Sethu|First|DAV|86|98
4|Theekshana|Second|DAV|97|86
5|Teju|First|Sangamithra|89|88
6|Theekshitha|Second|Sangamithra|99|100

Fields are separated by the field separator ("|")

Write a command to fetch the student details , who scored >=90 in mathematics and
>=90 in Science subject from Sangamithra school and display students details.

The display record format is:

StudentNo,Name,Standard,SchoolName and Average of Marks(of two subjects given in th


input data ) of the students in the Ascending order of the average of the scores,
if there are multiple records satisfies the given condition. If no records
satisfies the given condition then output is empty.

For more clarity, please refer to the sample testcase input and output below.

The input file with the data(testcase input / customized input) in the format
mentioned, automatically supplied as command line argument when you run the
script / command , you have written. Hence you don't need to worry / work on, " How
to bring the file to your script"?.

You just need to assume that a file is supplied to your script and read the file,
which is supplied as command line argument and process the data in the file towards
the given requirement.

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

Sample Testcase:

Input:

1|Latha|Third|Vikas|90|91
2|Neethu|Second|Meridian|92|94
3|Sethu|First|DAV|86|98
4|Theekshana|Second|DAV|97|86
5|Teju|First|Sangamithra|92|94
6|Theekshitha|Second|Sangamithra|99|100
Output:

5|Teju|First|Sangamithra|93
6|Theekshitha|Second|Sangamithra|99.5

awk 'BEGIN {FS = "|";}


{
if ($4 == "Sangamithra" && $5 >=90 && $6 >=90)
{
print $1"|"$2"|"$3"|"$4"|"($5+$6)/2;
}
}END {}' | sort -k5 -t'|'

You might also like