Advertisement
dzocesrce

[OS] English Premier League

Jan 21st, 2024
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.55 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $# -ne 1 ]
  3. then
  4.     echo "USAGE: `basename $0` source_folder"
  5.     exit 1
  6. fi
  7. FROM=$1
  8. touch results.txt
  9. #get all folders with the name koloX in the argument1 directory where X is a number
  10. folders=`ls -R $FROM | grep ^d | awk 'print $9' | grep ^kolo[0-9][0-9]*`
  11. for folder in $folders
  12. do
  13.     #each of deez folder has exactly one .rez file with tha same name so put its insides into our results.txt
  14.     echo `cat "${FROM}/${folder}/${folder}.rez"` >> results.txt
  15. done
  16. #leave out the rows that include losses, that info is not at our interest
  17. #not sure about the echo usage I must say but there shouldn't be a problem
  18. echo `cat results.txt | grep -v ^l` > results.txt
  19. #we are unaware which teams are participating, thus use uniq
  20. TEAMS=`cat results.txt | awk -F, '{print $2}' | uniq`
  21. #create a file that shows the standings of the league table with team name in one column and number of points in the other
  22. touch standings.txt
  23. GAMES=`cat results.txt`
  24. for team in $TEAMS
  25. do
  26.     points=0
  27.     #we wanna calculate number of points for each team by counting in how many rows they appear
  28.     #I suppose I should've gone with `cat results.txt | awk -F, '{print $2}' | grep ^$team | wc -l`, but I didn't think of it until now..
  29.     for game in $GAMES
  30.     do
  31.         team_name=`$game | awk -F, '{print $2}'`
  32.         if [ "$team_name" == "$team" ]
  33.         points=`expr $points + 1`
  34.     done
  35.     echo "$points $team" >> standings.txt
  36. done
  37. #sort the standings, as those with most points are on top
  38. sort -n -r standings.txt | cat standings.txt
  39.    
  40.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement