- 论坛徽章:
- 145
|
回复 9# elu_ligao
M for Maximum value
# It's OK for Normal data with positive number ( > 0 )
$ echo -e "-5\n-3\n7\n12\n3" | awk 'M<$1{M=$1}END{print M}'
12
# got the issue when all data were negative number ( < 0 )
# Note: The M will be 0, zero number, when we use it in number, M < $1,
# and the M didn't be assign and be empty
$ echo -e "-3\n-5\n-7\n-12\n-3" | awk 'M<$1{M=$1}END{print M}'
# check M variable to assign to the first number
$ echo -e "-5\n-3\n-7\n-12\n-3" | awk 'M==""||M<$1{M=$1}END{print M}'
-3
|
|