diff --git a/cs205_final_exam.sh b/cs205_final_exam.sh old mode 100644 new mode 100755 index 0befa75a..07a695c4 --- a/cs205_final_exam.sh +++ b/cs205_final_exam.sh @@ -9,3 +9,25 @@ # 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 + +# This script reads a file formatted like pokemon.dat and provides a summary report. + +# Store the filename in a variable +filename=$1 + +# Calculate the total number of Pokemon +total_pokemon=$(awk 'END {print NR}' $filename) + +# Calculate the average HP +avg_hp=$(awk '{hp_total+=$2} END {print hp_total/NR}' $filename) + +# Calculate the average Attack +avg_attack=$(awk '{attack_total+=$3} END {print attack_total/NR}' $filename) + +# Print the summary report +echo "# ======= SUMMARY OF $filename ======" +echo "# Total Pokemon: $total_pokemon" +echo "# Avg. HP: $avg_hp" +echo "# Avg. Attack: $avg_attack" +echo "# ======= END SUMMARY =======" diff --git a/screenshots/output.txt b/screenshots/output.txt new file mode 100644 index 00000000..09749e18 --- /dev/null +++ b/screenshots/output.txt @@ -0,0 +1,8 @@ +Script started on 2023-03-31 10:26:14-07:00 [TERM="xterm-256color" TTY="/dev/pts/1" COLUMNS="66" LINES="24"] +# ======= SUMMARY OF pokemon.dat ====== +# Total Pokemon: 801 +# Avg. HP: 0 +# Avg. Attack: 0 +# ======= END SUMMARY ======= + +Script done on 2023-03-31 10:26:14-07:00 [COMMAND_EXIT_CODE="0"]