I have a file containing data like so:
2012-01-02 GREEN 4
2012-01-02 GREEN 6
2012-01-02 GREEN 7
2012-01-02 BLUE 4
2012-01-02 BLUE 3
2012-01-02 GREEN 4
2012-01-02 RED 4
2012-01-02 RED 8
2012-01-02 GREEN 4
2012-01-02 YELLOW 5
2012-01-02 YELLOW 2
I can't always predict what the strings are going to be in the second column (so in the example above there are colours but the data file could contain any string in column two). There is always however a number in the third column (which I want the max value of for a paticular string in column two). Is awk able to:
- Pull out each of the unique strings in column 2?
- For each of the unique strings get the maximum associated value (so using the above you'd end up with the following)?:
2012-01-02 GREEN 7
2012-01-02 BLUE 4
2012-01-02 RED 8
2012-01-02 YELLOW 5
or would this be easier with Perl (or even shell)? any code examples much appreciated!