diff --git a/Pasted image.png b/Pasted image.png new file mode 100644 index 00000000..cce582b6 Binary files /dev/null and b/Pasted image.png differ diff --git a/cs205_final_exam.sh b/cs205_final_exam.sh old mode 100644 new mode 100755 index 0befa75a..378281db --- a/cs205_final_exam.sh +++ b/cs205_final_exam.sh @@ -1,11 +1,10 @@ -# TODO: Modify this file to create a shell script that is able to use awk to go through a file formatted like 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 POKEMON.DAT ====== -# Total Pokemon: [VALUE] -# Avg. HP: [VALUE] -# Avg. Attack: [VALUE] -# ======= END SUMMARY ======= - -# The "Avg." values should be calculated as mean values for the corresponding columns. -# 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 pokemon.dat. However, you can assume that any file passed to this script will be formatted exactly the way pokemon.dat is formatted. +#!/bin/bash +filename=$1 +total=$(awk 'END {print NR}' $filename) +avg_hp=$(awk '{sum += $3} END {print sum / NR}' $filename) +avg_attack=$(awk '{sum += $4} END {print sum / NR}' $filename) +echo "======= SUMMARY OF $filename ======" +echo "# Total Pokemon: $total" +echo "# Avg. HP: $avg_hp" +echo "# Avg. Attack: $avg_attack" +echo "# ======= END SUMMARY =======#