I have a input like this ; i need to filter the greater record value
cat;5 dog;3 bird;2 cat;3 dog;6 bird;8
for output a result like this
cat;5 dog;6 bird;8
I have a input like this ; i need to filter the greater record value
cat;5 dog;3 bird;2 cat;3 dog;6 bird;8
for output a result like this
cat;5 dog;6 bird;8
Please try the following:
#!/usr/bin/awk -f
BEGIN {
FS = OFS = ";";
}
{
if($2 > a[$1]) { a[$1] = $2 }
else { a[$1] = $2 }
}
END {
for(x in a) { print x, a[x] }
}