diff --git a/cs205_final_exam.sh b/cs205_final_exam.sh old mode 100644 new mode 100755 index d0d0d57c..384caf85 --- a/cs205_final_exam.sh +++ b/cs205_final_exam.sh @@ -1,4 +1,4 @@ -# TODO: Modify this file to create a shell script that is able to use awk to go through a file formatted like best_pokemon.dat and provides a printed report in the following format (where your script correctly calculates the values that go into the [VALUE] placeholders): + # ===== SUMMARY OF DATA FILE ===== # File name: [VALUE] # Total Pokemon: [VALUE] @@ -10,3 +10,28 @@ # The spacing and header formatting should match the above formatting description exactly. # There should be a comment explaining the purpose of each line in your shell script. # The data file will be passed in to the script as a positional parameter and will not necessarily be called best_pokemon.dat. However, you can assume that any file passed to this script will be formatted exactly the way best_pokemon.dat is formatted. + +if [ -z "$1" ]; then + echo "Usage: $0 datafile.dat" + exit 1 +fi + +# store the input file name in a variable +data_file="$1" + +# Use awk to calculate the results +read total_pokemon avg_hp avg_attack <<< $(awk 'NR > 1 && $1 != "#" {total++; sum_hp += $6; sum_attack += $7} + END {print total, sum_hp/total, sum_attack/total}' "$data_file") + +# print the results +echo "===== SUMMARY OF DATA FILE =====" +echo +echo " File name: $data_file" +echo +echo " Total Pokemon: $total_pokemon" +echo +printf " Avg. HP: %.2f\n" "$avg_hp" +echo +printf " Avg. Attack: %.2f\n" "$avg_attack" +echo +echo "===== END SUMMARY =====" diff --git a/screenshots/Screenshot from 2024-05-07 23-41-27.png b/screenshots/Screenshot from 2024-05-07 23-41-27.png new file mode 100644 index 00000000..23ed99f8 Binary files /dev/null and b/screenshots/Screenshot from 2024-05-07 23-41-27.png differ