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 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -