Just want to say this is great resources for all thing Unix!!
cat tmp.txt
A 3
C 19
A 2
B 5
A 1
A 0
C 13
B 9
C 1
Desired output:
A 3
B 9
C 19
The following work but I am wondering if there is a better way to do it:
Looking for better performance on larger and more complex file.
awk '{print $1}' tmp.txt | sort | uniq > grep.lst
sort -k1,1 -k2,2nr tmp.txt > tmp.sort.txt
for i in `cat grep.lst`
do
grep $i tmp.sort.txt | head -1 >> good.out
done
cat good.out
A 3
B 9
C 19
$2>M[$1] - This part is testing if current value in column two is bigger than maximum value saved so far. If it is, then the value is replaced with the code that you described.