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

Added the script require to analyze pokemon data, created a new file … #431

Open
wants to merge 1 commit 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
42 changes: 30 additions & 12 deletions cs205_final_exam.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
# 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]
# Total Pokemon: [VALUE]
# Avg. HP: [VALUE]
# Avg. Attack: [VALUE]
# ===== END SUMMARY =====

# The "Avg." values should be calculated as mean values for the corresponding columns.
# 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.
#!/bin/bash

# Purpose: Check if a file is provided as an argument
if [ $# -eq 0 ]; then
echo "Usage: $0 <data_file>"
exit 1
fi

# Purpose: Store the file name passed as argument
file_name="$1"

# Purpose: Print the header for the summary
echo "===== SUMMARY OF DATA FILE ====="
echo -n " File name: "
echo "[${file_name}]"

# Purpose: Calculate and print total number of Pokemon
total_pokemon=$(awk 'END {print NR}' "$file_name")
echo " Total Pokemon: ${total_pokemon}"

# Purpose: Calculate and print average HP
avg_hp=$(awk '{sum += $5} END {print sum/NR}' "$file_name")
echo " Avg. HP: ${avg_hp}"

# Purpose: Calculate and print average Attack
avg_attack=$(awk '{sum += $4} END {print sum/NR}' "$file_name")
echo " Avg. Attack: ${avg_attack}"

# Purpose: Print end of summary
echo "===== END SUMMARY ====="
Binary file added screenshots/Output_Final_Exam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.