如何找到两个值文件,并使用theese作为变量? [英] How to find two values in file and use theese as variables?

查看:120
本文介绍了如何找到两个值文件,并使用theese作为变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何才能找到和存储为变量的两个数字,然后按RX字节:TX字节:在这个文件?
我想用一个OpenWrt的路由器theese值来计算一个简单的电流监控器的带宽bash脚本。

How can I find and store as variables the two numbers followed by "RX bytes:" and "TX bytes:" in this file? I want to calculate with theese values in a simple current bandwidth monitor bash script using an OpenWrt router.

为/ dev / BAND1:

/dev/band1:

br-lan    Link encap:Ethernet  HWaddr 
      inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:3848954 errors:0 dropped:21234 overruns:0 frame:0
      TX packets:4213574 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:1206316927 (1.1 GiB)  TX bytes:3385060741 (3.1 GiB)

感谢您的帮助!

推荐答案

例如,RX字节,你可以:

for example, the RX bytes, you could:

rxBytes=$(yourcmd|grep -Po '(?<=RX bytes:)\d+')

与TX取代RX你得到另一个变量

replace the RX with TX you get another variable

修改

您也可以去使用awk:

you could also go with awk:

rxBytes=$(awk -F'RX bytes:' 'NF>1{sub(/ .*$/,"",$2);print $2}')

变动的RX - > TX拿到另一个

chg the RX -> TX to get the other one.

这篇关于如何找到两个值文件,并使用theese作为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆