How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone,

This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file):

ID, Code, Value, Store SP|01, AABBCDE, 15, 3  SP|01, AABBCDE, 14, 2  SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3  SP|02, AABBCED, 15, 2  SP|01, AABBCDF, 12, 3 SP|01, AABBCDD, 13, 2  SP|02, AABBCDF, 9, 2 SP|01, AABBCDF, 8, 3

The idea is to print rows with the 2 highest values in "Value" column for identical values in "Code" (And also keep the headers)
Exemple of output files:

ID Code Value Store SP|01, AABBCDE, 16, 3 SP|01, AABBCDE, 15, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDD, 13, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDF, 12, 3

I'm new to Linux and have a bit of knowledge in very basic use of AWK, sed, grep ect but I'm unsure how to manipulate the file to get the output as stated above.

Any help would be very much appreciated!

Hi you can use sort command to sort the data depending upon the column u wanted and then u get the top two example i have file new with random data

/var/backup # cat new1                                                            
1,2,3,4,5,6                                                                     
7,9,10,456,123                                                                  
8,123,678,900,100                                                               
/var/backup # sort -nrk2 -t, new1|head -2                                         
8,123,678,900,100                                                               
7,9,10,456,123                                                                  
/var/backup #