Skip to content
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