有sed -n + nth字符的自由-g。

[英]free -g with sed -n plus nth character


I am trying to create a script to display just one of the numbers from the free command. In my case, the number I want is on the 2nd line of the free -g output and at character slot 43. The original output of free -g is:

我正在尝试创建一个脚本,以显示来自free命令的一个数字。在我的例子中,我想要的数字是在自由-g输出的第二行和字符槽43。自由-g的原始输出为:

              total       used       free     shared buff/cache  available
Mem:              3          0          2          0          0          2     
Swap:             3          0          3          

So far I have gotten the 2nd line to display with:

到目前为止,我已经得到了第2行显示:

free -g | sed -n 2p
Mem:              3          0          2          0          0          2

I need just the 43rd character of that line or the 4th column? I have looked into printf and cut but get a grody syntax error.

我只需要这条线的第43个字符或者第四列?我已经查看了printf和cut,但是得到了一个grody语法错误。

1 个解决方案

#1


2  

If a line contains Mem: print from this line column 4:

如果一行包含Mem:从这行第4列打印:

free -g | awk '/Mem:/ {print $4}'

Output:

输出:

2
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2017/09/23/d362c9b3d47ca3df8c7458c1907d3344.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告