如何将第3列和第4列中的值舍入为最接近的整数然后打印所有4列?

时间:2013-11-24 08:57:56

标签: linux awk

for file in /tmp/CRreport/out/ny.01.txt  /tmp/CRreport/out/ny.02.txt ; do
   cat $file
   echo
done | 
sed '/^$/d' | awk '{ 
   date=$1 " " $2
   used[date] += $3
   usedp[date] += $4
   count[date]++
}
END { 
   for (d in used) {
     print d, "\t" used[d]/count[d]/1024, "\t" usedp[d]/count[d] 
   } 
}' | sort -n -k2`

November 01     27.6085         84.3647
November 02     27.6154         84.3854
November 03     27.7986         84.9451
November 04     27.4744         83.9539
November 05     27.5167         84.0833
November 06     27.6493         84.4885

如何将第3和第4列中的值四舍五入为最接近的整数,然后打印所有4列?

1 个答案:

答案 0 :(得分:1)

有人这样吗?

awk '{print $1,$2,int($3),int($4)}' file
November 01 27 84
November 02 27 84
November 03 27 84
November 04 27 83
November 05 27 84
November 06 27 84