I have file
try.txt
RAM 142 149 131
Cache 456 152 184
I want to compute maximum, minimum, median
for each value of the line
Expected Output:
Min= 131 Max=149 Median=142
Min=152 Max=456 Median=184
Here is what I have tried.:
for itr in {1..2}
do
awk "FNR == $itr { c=0;size=NF;
for(i=2;i<=size;i++)
arr[c++] =$i;
for(i=0;i<c;i++)
{
for (j=i+1;j<c;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
print "Min=" arr[0] "Max=" arr[2] "Median=" arr[1]
}" try.txt
done
Inorder to approach the output, I created an array to hold the $2, $3, $4 of value of each line, but unfortunately, it is not taking. The main purpose of creating an array to compute median, as the element must be in sorted order to compute median. Please help me in creating an array for each line's value to compute min, max, median.