Description
For this assignment you can use sed, grep and awk commands in a shell script to do the desired tasks. You can use man pages to know more about these commands. You will also need to use output redirection (>, >>, or some equivalent method) to write to a file.
[1] Write a shell script and name it as lab.sh, which will take exactly two filenames as arguments. If exactly two names are not provided, the script prints a usage message and exits, otherwise the script do what is described next. Usage message tells the user how to use the script.
[2] Till this step, you have provided two filenames to the script. The first file name is an input file, and the second one is an output file. You need to check whether the input file exists or not. If the input file does not exist (How do you test that in bash?), the script generates an appropriate error message and exits. If the input file exist then proceed to next step.
[3] The input file is CSV (Comma Separated Values) file representing a dataset of colleges. The data is divided into different columns:
Name, PredominantDegree, HighestDegree, FundingModel, Region, Geography, AdmissionRate, ACTMedian, SATAverage, AverageCost, Expenditure, AverageFacultySalary, MedianDebt, AverageAgeofEntry, MedianFamilyIncome, MedianEarnings.
Now, your script should print the following fields in ALL lines in the input file to output file (the second argument) by replacing “,”(comma) to “ ”(space).
Name, PredominantDegree, HighestDegree, Region, Geography, AdmissionRate, AverageCost, Expenditure.
If any data already exists in the output file then it should be overwritten.
[5] The script should compute the average admission rate by grouping the colleges with respect to Geography Column of the dataset and save it to the output file(second argument). Be careful that the script should not overwrite the output file. The output should be saved as follows:
Geography: Average Admission Rate
Mid-size City: XYZ
Small City: ABC
…..
Note that XYZ,ABC etc should be replaced by actual output. This way you have to save average admission rate for all geographical area.
[6] The script should save the top five colleges to the output file who have maximum MedianEarnings. Be careful that the script should not overwrite the output file.
Any question about this assignment should be directed to: Preeti Singh <preeti@cse.iitk.ac.in>.
1




Reviews
There are no reviews yet.