Input file consists of 3 fields separated by "|" as follows:
TeamId|TeamName|TotalPlayers
TeamId consists of unique numbers. TeamName consists of several Premier league football teams and corresponding no of players in TotalPlayers field.
2 of the records are as follows:(these records belong to one of the visible test cases)
103|Manchester United|12
105|Manchester City|13
Code requirement:
I had to output the TeamName which starts with Manchester and has the most number of players. If no Team starts with Manchester, then it should not be any output. i.e. In the above test case the output should be Manchester City.
My solution:
awk 'BEGIN{FS = "|";OFS = ",";}{if($2 ~ /^Manchester/){print $2, $3}}' | sort -n -k2 | awk -F , '(NR==1){print $1}'
This provided the expected output for normal test cases but hidden test cases were failed. What changes can I make to this or any other easier way to achieve the same...
Also recommend any websites where I can practice these kind of unix coding problems by solving.