Artificial intelligent assistant

Using awk to divide the number in each line of a file by the maximum value in that file I have a file like this: 0.0451660231 0.0451660231 0.0527343825 0.3933106065 0.3970947862 0.0489502028 0.3592529595 0.3592529595 0.3592529595 0.3630371392 0.3630371392 0.3668213189 0.4008789659 0.1397705227 and I want to divide each line by the maximum value. I did cut -f1 -d"," CVBR1_hist | sort -n | tail -1 > maximum awk -v c=$maximum '{print $1/c}' CVBR1_hist > CVBR1_norm I have this error: awk: cmd. line:1: (FILENAME=CVBR1_hist FNR=1) fatal: division by zero attempted I don't know how to solve it. Can anyone help me?

Awk give you an error because the variable "c" is set equal to an empty variable. $maximum isn't yet set.

You should do:


awk -v c=`cat maximum` '{print $1/c}' CVBR1_hist > CVBR1_norm


Here is where your command failed.

Better way: don't go through a temporary file but store the maximum value in a variable, like the Kusalananda's answer.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy b5ac3bb7d64751cf22f46b0f28d92b93