awk: find minimum and maximum in column

前端 未结 4 414
慢半拍i
慢半拍i 2020-12-09 17:00

I\'m using awk to deal with a simple .dat file, which contains several lines of data and each line has 4 columns separated by a single space. I want to fin

4条回答
  •  一生所求
    2020-12-09 17:52

    Awk guesses the type.

    String "10" is less than string "4" because character "1" comes before "4". Force a type conversation, using addition of zero:

    min=`awk 'BEGIN{a=1000}{if ($1<0+a) a=$1} END{print a}' mydata.dat`
    max=`awk 'BEGIN{a=   0}{if ($1>0+a) a=$1} END{print a}' mydata.dat`
    

提交回复
热议问题