Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mjd555_spring2024 Final #445

Open
wants to merge 2 commits into
base: Spring2024
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions cs205_final_exam.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,32 @@
# 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.

awk '
# begin the AWK
BEGIN{HPPIVOT=7}
# Get the HP from the 7th column from the right.
BEGIN{ATKPIVOT=6}
# Get the attack from the 6th column on the right.
NR>1 {HPSUM+=$(NF - HPPIVOT)}
# Add every line HP stat to a variable.
NR>1 {ATKSUM+=$(NF - ATKPIVOT)}
# Add every line attack stat to a variable.
END{MEANHP = HPSUM / (NR - 1)}
# Divide every line HP by every line to get an average.
END{MEANATK = ATKSUM / (NR - 1)}
# Likewise, divide the attack sum by the lines.
END{ print "===== SUMMARY OF DATA FILE ====="}
# print the header
END{ print " File name: " (FILENAME) }
# Self explanatory, just prints the FILENAME for the filename.
END{ print " Total Pokemon: " $(1) }
# Since some pokemon are counted multiple times (For variants), just use the 1st field on the last line.
END{ print " Avg. HP: " MEANHP}
# Print the mean HP
END{ print " Avg. Attack: " MEANATK}
# Print the mean attack
END{ print "===== END SUMMARY ====="}
# Print the footer
' $1
# Take in the first argument to get the file
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.