file- xyz.161209:/userlogs/logs/reports 355G 195G 150G 57% /home xyz.161209:/userlogs/logs/reports 355G 197G 148G 58% /home xyz.161209:/userlogs/logs/reports 355G 201G 145G 59% /home xyz.161210:/userlogs/logs/reports 355G 218G 129G 63% /home xyz.161210:/userlogs/logs/reports 355G 223G 124G 65% /home xyz.161210:/userlogs/logs/reports 355G 226G 121G 66% /home xyz.161211:/userlogs/logs/reports 355G 210G 136G 61% /home xyz.161211:/userlogs/logs/reports 355G 220G 127G 64% /home xyz.161211:/userlogs/logs/reports 355G 173G 171G 51% /home Result xyz.161209:/userlogs/logs/reports 355G 201G 145G 59% /home xyz.161210:/userlogs/logs/reports 355G 226G 121G 66% /home xyz.161211:/userlogs/logs/reports 355G 220G 127G 64% /home For every first column that contains sorted date, group by first column and display only the row that contains fifth column with maximum %.
Here's what I have tried,however I can't get the desired output. Anyone can help me?
awk -F, '{if ((a[substr($1,5,6)] == substr($1,5,6)) && (b[substr($5,1,2)] < substr($5,1,2)))b[substr($5,1,2)]=substr($5,1,2);}END{for(i in a){print i,a[i];}}' test.txt