简体   繁体   English

在Linux中打印多于一列的总和

[英]Print sums of more than one column in Linux

I want to get sums of two columns' values. 我想获取两列值的总和。 I want each result separately. 我想要每个结果分开。 Here is my values: 这是我的价值观:

command 命令

iostat -x 1 2 \
| perl -e 'local $/=""; @p=<STDIN>; print @p[4];' \
| awk '{ print $6 " " $7}' \
| grep -v rsec

output 产量

0.00 1608.00
22.00 0.00
10.00 1608.00
0.00 1312.00
0.00 0.00
0.00 0.00
0.00 296.00

I want this result 我想要这个结果

32.00 4824.00

Here is what i tried: 这是我尝试过的:

iostat -x 1 2 \
| perl -e 'local $/=""; @p=<STDIN>; print @p[4];' \
| awk '{ print $6 " " $7}' \
| grep -v rsec \
| awk '{ SUM += $1 SUM2 += $2} END { print SUM " " SUM2}'

This command gives me a syntax error. 此命令给我一个语法错误。 What's the solution for this? 有什么解决方案?

According to the man page, commands in awk can be separated by newlines, semicolons, or both. 根据手册页, awk命令可以用换行符,分号或两者分隔。 Your two commands are not separated by any of those things. 您的两个命令之间没有任何分隔。 The solution is to write: 解决方法是编写:

| awk '{ SUM += $1; SUM2 += $2} END { print SUM " " SUM2}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM