我试图从本质上在文件的每一行上运行命令。以下是到目前为止的内容。我希望能够获取每一行,从中获取最后一列,对整数运行命令,如果它不等于零,则回显整行。我似乎遇到了错误,似乎无法找出错误所在。
#!/bin/bash
IFS=\n
file=`cat /proc/user_beancounters`
for line in "$file"
do
last_col=`echo "$line" | awk '{print $(NF)}'`
if [ $last_col -ne 0 ]; then
echo $last_col
fi
done
/ proc / user_beancounters的内容:
Version: 2.5
uid resource held maxheld barrier limit failcnt
34579: kmemsize 28694400 33435648 67108864 67108864 0
lockedpages 0 0 64 64 0
privvmpages 473539 581717 786432 786432 176
shmpages 26821 26821 43008 43008 0
dummy 0 0 9223372036854775807 9223372036854775807 0
numproc 113 159 500 500 0
physpages 199504 208572 524288 524288 0
vmguarpages 0 0 98304 98304 0
oomguarpages 188782 191010 6144 6144 0
numtcpsock 35 37 160 160 0
numflock 8 11 100 100 0
numpty 1 1 200 200 0
numsiginfo 0 36 500 500 0
tcpsndbuf 616080 650960 8388608 8388608 0
tcprcvbuf 577800 621600 8388608 8388608 0
othersockbuf 108664 135616 8388608 8388608 0
dgramrcvbuf 0 16184 8388608 8388608 0
numothersock 116 128 500 500 0
dcachesize 8375457 8388258 8388608 8388608 0
numfile 2627 2915 8192 8192 0
dummy 0 0 9223372036854775807 9223372036854775807 0
dummy 0 0 9223372036854775807 9223372036854775807 0
dummy 0 0 9223372036854775807 9223372036854775807 0
numiptent 168 168 9999999 9999999 0
在上面的示例中,我希望脚本从本质上挑选出“ privvmpages”已失败多次,因此回显了这一行:
privvmpages 473539 581717 786432 786432 176
或者,如果可能的话,仅使用名称“ privvmpages”和数字“ 176”
提前致谢
awk 'NF>2 && $NF' file