I am trying to parse some CSV files using awk.
The CSV file I am working with looks like this:
fnName,minAccessTime,maxAccessTime
getInfo,300,600
getStage,600,800
getStage,600,800
getInfo,250,620
getInfo,200,700
getStage,700,1000
getInfo,280,600
I need to find the minimum, maximum and average figures for columns 2 and 3, both across all data and individual functions.
This
awkscript should give you all the skills necessary to get what you want.It basically runs through all lines in your input file, ignoring those where the second field is
minAccessTime(the CSV header).On all other records, it updates the count of, minimum-of-minima, maximum-of-minima, minimum-of-maxima, maximum-of-maxima, sum-of-minima, and sum-of-maxima for both the overall data plus each individual function name.
The former is stored in
count,min_min,max_min,min_max,max_max,sum_minandsum_max. The latter are stored in associative arrays with similar names (with_arrappended).Then, once all records are read, the
ENDsection outputs the information.Storing that script into
qq.awkand placing your sample data intoqq.in, then running:generates the following output, which I’m relatively certain will give you every possible piece of information you need: