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

Spring2024 Pull Request #437

Open
wants to merge 3 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
1 change: 1 addition & 0 deletions Screenshots
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file added cs205_final.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions cs205_final_exam.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,38 @@
# Total Pokemon: [VALUE]
# Avg. HP: [VALUE]
# Avg. Attack: [VALUE]

if [ $# -ne 1 ]; then
echo "Usage: $0 <data file>"
exit 1
fi

filename=$1

awk -v file="$filename" -F '\t' 'BEGIN {
total_hp = 0;
total_attack = 0;
count = 0;
}

NR > 1 {
total_hp += $5;
total_attack += $6;
count++;
}

END {
avg_hp = total_hp / count;
avg_attack = total_attack / count;

print "===== SUMMARY OF DATA FILE =====";
print " File name: " file;
print " Total Pokemon: " count;
printf " Avg. HP: %.2f\n", avg_hp;
printf " Avg. Attack: %.2f\n", avg_attack;
print "===== END SUMMARY =====";
}' "$filename"

# ===== END SUMMARY =====

# The "Avg." values should be calculated as mean values for the corresponding columns.
Expand Down