我有一个包含许多列的文件,我想在第 11 列和第 9 列之间执行划分并在新行中打印。
ram, gopal, shayam, raj, kamal, shekhar, uday, bhanu, 10,uat,20
ram, gopal, shayam, raj, kamal, shekhar, uday, bhanu, 20,uat,60
ram, gopal, shayam, raj, kamal, shekhar, uday, bhanu, 30,uat,90
输出应如下所示 -
ram, gopal, shayam, raj, kamal, shekhar, uday, bhanu, 10,uat,20,2%
ram, gopal, shayam, raj, kamal, shekhar, uday, bhanu, 20,uat,60,3%
ram, gopal, shayam, raj, kamal, shekhar, uday, bhanu, 30,uat,90,3%
致命除以 0 错误:
$ awk -F, -vOFS=, '{print $0,($9==0?0:$11/$9)"%"}' /cygdrive/c/test/kpi/test.csv
awk: cmd. line:1: (FILENAME=/cygdrive/c/test/kpi/test.csv FNR=1) fatal: division by zero attempted