Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Log file path
- LOG_FILE="/home/capodecima/odamex/duelentry.log"
- OUTPUT_FILE="/home/capodecima/odamex/duel_stats_output.log" # File to save parsed results
- # Check if the log file exists
- if [[ ! -f "$LOG_FILE" ]]; then
- echo "Log file $LOG_FILE not found!"
- exit 1
- fi
- # Clear or create output file
- > "$OUTPUT_FILE"
- # Start saving results
- echo "Parsing duel stats from $LOG_FILE..." | tee -a "$OUTPUT_FILE"
- # Extract Game information: Game winner, fraglimit, and timelimit
- grep -E "Game won by|Fraglimit|Timelimit" "$LOG_FILE" | while read -r line; do
- if [[ "$line" =~ "Game won by" ]]; then
- echo "Winner: $(echo $line | sed 's/.*Game won by \(.*\)!/\1/')" | tee -a "$OUTPUT_FILE"
- elif [[ "$line" =~ "Fraglimit" ]]; then
- echo "Fraglimit: $(echo $line | sed 's/Fraglimit: \([0-9]*\)/\1/')" | tee -a "$OUTPUT_FILE"
- elif [[ "$line" =~ "Timelimit" ]]; then
- echo "Timelimit: $(echo $line | sed 's/Timelimit: \(.*\)/\1/')" | tee -a "$OUTPUT_FILE"
- fi
- done
- # Extract player stats (ID, Name, Frags, Deaths, K/D, Time) after "DEATHMATCH"
- echo -e "\nPlayer Stats:" | tee -a "$OUTPUT_FILE"
- # Flag to indicate when we start capturing stats
- START_CAPTURE=false
- # Read through the log file line by line
- while read -r line; do
- if [[ "$line" =~ "DEATHMATCH" ]]; then
- START_CAPTURE=true
- fi
- if [[ "$START_CAPTURE" == true ]]; then
- # Look for the stats section in the log where each line has player stats (ID, Address, Name, Frags, Deaths, K/D, Time)
- if [[ "$line" =~ ^[0-9]+ ]]; then
- # Extract stats from each line using awk for better handling of spaces
- ID=$(echo "$line" | awk '{print $1}')
- NAME=$(echo "$line" | awk '{print $3}')
- FRAGS=$(echo "$line" | awk '{print $4}')
- DEATHS=$(echo "$line" | awk '{print $5}')
- KD=$(echo "$line" | awk '{print $6}')
- TIME=$(echo "$line" | awk '{print $7}')
- # Save extracted stats to the output file
- echo "ID: $ID Name: $NAME Frags: $FRAGS Deaths: $DEATHS K/D: $KD Time: $TIME" | tee -a "$OUTPUT_FILE"
- fi
- fi
- done < "$LOG_FILE"
- echo -e "\nStats parsing complete. Results saved to $OUTPUT_FILE" | tee -a "$OUTPUT_FILE"
Advertisement
Add Comment
Please, Sign In to add comment