linux - Unix shell finding the max and min values and printing the line from a file -
i have file has numbers @ first column.
100,red 101,blue 102,black
i should write shell script print line max , min numbers.
max=0 cat file.txt|while read line fir=`echo $line|awk '{print $2}'` sec=`echo $line|awk '{print $3}'` if [ $fir -gt $max ]; max=$fir fi if [ $sec -gt $max ];then max=$sec fi done grep $max file.txt
this tried far finding max.
for min value:
[bash]$ cut -f1 -d"," file_name | sort -n | head -1
for max value:
[bash]$ cut -f1 -d"," file_name | sort -n | tail -1