file input
aaaa,52C
aaaa,50C
bbbb,50C
bbbb,58C
aaaa,52C
bbbb,50C
aaaa,30C
bbbb,58C
cccc,60C
i want to print uniq lines with its max value of column2
expected output
aaaa,52C
bbbb,58C
cccc,60C
tks
file input
aaaa,52C
aaaa,50C
bbbb,50C
bbbb,58C
aaaa,52C
bbbb,50C
aaaa,30C
bbbb,58C
cccc,60C
i want to print uniq lines with its max value of column2
expected output
aaaa,52C
bbbb,58C
cccc,60C
tks
Try below
sort -n -t, -k 2,2 filename|awk -F, '{A[$1]=$2}END{for (i in A){print i","A}}'
awk -F, '!($1 in max) || $2>max[$1] {max[$1]=$2} END {for (i in max) print i FS max}' input
Before reaching the END you don't know what the maximum is, hence cannot immediately print anything - a simple grep cannot work.
Radius,
Your specification is extremely vague. Is the 2nd field to be treated as
If it is a temperature, are some values ever given in Fahrenheit or Kelvin? Does the sort need to convert Centigrade, Fahrenheit, and Kelvin to a common scale and sort by increasing temperatures independent of scale used? Or, will all temperatures be reported in Centigrade?
If it is something else, what?
So far, vidyadhar85's sort command assumes #2 and MadeInGermany's awk script assumes #1.
Don Cragun's 4. item could be hexadecimal as well...
Yes the spec needs to be refined!
Assuming lexicographic/string sort, and avoiding the loss of order occurring when using for (i in Arr) - well, had the input file had any order, that is - , this might satisfy your request:
$ sort file | awk -F, 'NR>1 && TMP1 != $1 {print TMP0} {TMP0=$0; TMP1=$1} END {print TMP0}'
aaaa,52C
bbbb,58C
cccc,60C