diff --git a/cs205_final_exam.sh b/cs205_final_exam.sh index d0d0d57c..67d8f028 100644 --- a/cs205_final_exam.sh +++ b/cs205_final_exam.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # 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] @@ -10,3 +12,40 @@ # 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. + + +FILE="$1" + +echo $FILE + +if [ -f $FILE ]; then + echo "$FILE exists!" +else + echo "$FILE does not exist!" +fi + +# create totals variables and set to 0 +awk -F'\t' 'BEGIN { + file_name = ARGV[1] + total_pokemon = 0 + total_hp = 0 + total_attack = 0 +} + +NR > 1 { + total_pokemon++ + total_hp += $6 + total_attack += $7 +} + +END { + avg_hp = total_hp / total_pokemon + avg_attack = total_attack / total_pokemon + + printf("# ===== SUMMARY OF DATA FILE =====\n") + printf("# File name: %s\n", file_name) + printf("# Total Pokemon: %d\n", total_pokemon) + printf("# Avg. HP: %.2f\n", avg_hp) + printf("# Avg. Attack: %.2f\n", avg_attack) + printf("# ===== END SUMMARY =====\n") +}' "$FILE" \ No newline at end of file diff --git a/screenshots/Final terminal screenshots .png b/screenshots/Final terminal screenshots .png new file mode 100644 index 00000000..42eebc81 Binary files /dev/null and b/screenshots/Final terminal screenshots .png differ