[英]Assign awk multiple variables
I'm using this command to check all sshd processes and CPU USAGE and CMD for sshd deamon: 我正在使用此命令检查所有sshd进程以及sshd deamon的CPU USAGE和CMD:
ps -C sshd -o %cpu,cmd
example of output: 输出示例:
%CPU CMD
0.0 sshd: root [priv]
0.0 sshd: aadmin@pts/1
After that i've used: 之后我用过:
ps -C sshd -o %cpu,cmd | awk '!/%CPU/ {print $1, $3}'
Output: 输出:
0.0 root
0.0 aadmin@pts/1
To sort CPU USAGE and third line, what i want is to assign awk
output var to have output like this for multiple processes and in separate lines. 要对CPU USAGE和第三行进行排序,我想要的是为多个进程和单独的行分配awk
输出var以具有这样的输出。
CPU_USAGE=0.0 USER=root
CPU_USAGE=0.0 USER=aadmin@pts/1
I've tried to assign variable to awk with awk -v
but without success 我试图用awk -v
为awk分配变量,但没有成功
ps -C sshd -o %cpu,cmd | awk '!/%CPU/ {printf("CPU_USAGE=%s USER=%s\n", $1, $3)}'
You just have to format your print
statement, for that, use printf
. 您只需要格式化print
语句,为此,使用printf
。
Or shorter: 或更短:
ps -C sshd -o %cpu,cmd | awk '!/%CPU/ {print "CPU_USAGE="$1, "USER="$3}'
Hope this is what u want. 希望这是你想要的。 Your question was not clear otherwise... 你的问题不清楚,否则......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.