capodecima

test

Mar 26th, 2025
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Log file path
  4. LOG_FILE="/home/capodecima/odamex/duelentry.log"
  5. OUTPUT_FILE="/home/capodecima/odamex/duel_stats_output.log" # File to save parsed results
  6.  
  7. # Check if the log file exists
  8. if [[ ! -f "$LOG_FILE" ]]; then
  9. echo "Log file $LOG_FILE not found!"
  10. exit 1
  11. fi
  12.  
  13. # Clear or create output file
  14. > "$OUTPUT_FILE"
  15.  
  16. # Start saving results
  17. echo "Parsing duel stats from $LOG_FILE..." | tee -a "$OUTPUT_FILE"
  18.  
  19. # Extract Game information: Game winner, fraglimit, and timelimit
  20. grep -E "Game won by|Fraglimit|Timelimit" "$LOG_FILE" | while read -r line; do
  21. if [[ "$line" =~ "Game won by" ]]; then
  22. echo "Winner: $(echo $line | sed 's/.*Game won by \(.*\)!/\1/')" | tee -a "$OUTPUT_FILE"
  23. elif [[ "$line" =~ "Fraglimit" ]]; then
  24. echo "Fraglimit: $(echo $line | sed 's/Fraglimit: \([0-9]*\)/\1/')" | tee -a "$OUTPUT_FILE"
  25. elif [[ "$line" =~ "Timelimit" ]]; then
  26. echo "Timelimit: $(echo $line | sed 's/Timelimit: \(.*\)/\1/')" | tee -a "$OUTPUT_FILE"
  27. fi
  28. done
  29.  
  30. # Extract player stats (ID, Name, Frags, Deaths, K/D, Time) after "DEATHMATCH"
  31. echo -e "\nPlayer Stats:" | tee -a "$OUTPUT_FILE"
  32.  
  33. # Flag to indicate when we start capturing stats
  34. START_CAPTURE=false
  35.  
  36. # Read through the log file line by line
  37. while read -r line; do
  38. if [[ "$line" =~ "DEATHMATCH" ]]; then
  39. START_CAPTURE=true
  40. fi
  41.  
  42. if [[ "$START_CAPTURE" == true ]]; then
  43. # Look for the stats section in the log where each line has player stats (ID, Address, Name, Frags, Deaths, K/D, Time)
  44. if [[ "$line" =~ ^[0-9]+ ]]; then
  45. # Extract stats from each line using awk for better handling of spaces
  46. ID=$(echo "$line" | awk '{print $1}')
  47. NAME=$(echo "$line" | awk '{print $3}')
  48. FRAGS=$(echo "$line" | awk '{print $4}')
  49. DEATHS=$(echo "$line" | awk '{print $5}')
  50. KD=$(echo "$line" | awk '{print $6}')
  51. TIME=$(echo "$line" | awk '{print $7}')
  52.  
  53. # Save extracted stats to the output file
  54. echo "ID: $ID Name: $NAME Frags: $FRAGS Deaths: $DEATHS K/D: $KD Time: $TIME" | tee -a "$OUTPUT_FILE"
  55. fi
  56. fi
  57. done < "$LOG_FILE"
  58.  
  59. echo -e "\nStats parsing complete. Results saved to $OUTPUT_FILE" | tee -a "$OUTPUT_FILE"
Advertisement
Add Comment
Please, Sign In to add comment