我有一个包含许多列的文件,我想在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
答案 0 :(得分:3)
可以这样做:
$ awk -F, -vOFS=, '{print $0,$11/$9"%"}' file
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%