Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# -ne 1 ]
- then
- echo "USAGE: `basename $0` source_folder"
- exit 1
- fi
- FROM=$1
- touch results.txt
- #get all folders with the name koloX in the argument1 directory where X is a number
- folders=`ls -R $FROM | grep ^d | awk 'print $9' | grep ^kolo[0-9][0-9]*`
- for folder in $folders
- do
- #each of deez folder has exactly one .rez file with tha same name so put its insides into our results.txt
- echo `cat "${FROM}/${folder}/${folder}.rez"` >> results.txt
- done
- #leave out the rows that include losses, that info is not at our interest
- #not sure about the echo usage I must say but there shouldn't be a problem
- echo `cat results.txt | grep -v ^l` > results.txt
- #we are unaware which teams are participating, thus use uniq
- TEAMS=`cat results.txt | awk -F, '{print $2}' | uniq`
- #create a file that shows the standings of the league table with team name in one column and number of points in the other
- touch standings.txt
- GAMES=`cat results.txt`
- for team in $TEAMS
- do
- points=0
- #we wanna calculate number of points for each team by counting in how many rows they appear
- #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..
- for game in $GAMES
- do
- team_name=`$game | awk -F, '{print $2}'`
- if [ "$team_name" == "$team" ]
- points=`expr $points + 1`
- done
- echo "$points $team" >> standings.txt
- done
- #sort the standings, as those with most points are on top
- sort -n -r standings.txt | cat standings.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement