I have tried to do it separately, and I am getting the right result, but I need help to combine the two. This is the csv file:
maruti swift 2007 50000 5
honda city 2005 60000 3
maruti dezire 2009 3100 6
chevy beat 2005 33000 2
honda city 2010 33000 6
chevy tavera 1999 10000 4
toyota corolla 1995 95000 2
maruti swift 2009 4100 5
maruti esteem 1997 98000 1
ford ikon 1995 80000 1
honda accord 2000 60000 2
fiat punto 2007 45000 3
I am using this script to sort by first field:
BEGIN { print "========Sorted Cars by Maker========"
}
{arr[$1]=$0}
END{
PROCINFO["sorted_in"]="@val_str_desc"
for(i in arr)print arr[i]
}
I also want to run a sort on the year($3) ascending in the same script. I have tried many ways but to no avail. A little help to do that would be appreciated..
Assumptions:
maruti+2009) so we'll maintain the input orderingOne idea using
sort:Another idea using
GNU awk(for arrays of arrays andPROCINFO["sorted_in"]):Both of these generate: