Parsing data from ifconfig with awk or sed?

前端 未结 3 1840
悲&欢浪女
悲&欢浪女 2021-01-07 06:18

I am trying to parse some data from ifconfig output with sed, but I am not able to do it correctly. I want the command to extract just the number I am after.

For exa

3条回答
  •  渐次进展
    2021-01-07 06:44

    By default, sed prints out each line of the input, after any changes you've made to the line. Since you only want to print out something from the line with "RX bytes", you tell sed not to print every line (-n). So you want to specify the range on which the substitution should be performed, only the line that matches RX bytes, and then do the substitution and explicitly print the results.

    ifconfig eth1 | sed '/RX bytes/{s|.*RX bytes:\([0-9]*\).*|\1|; p}'
    

提交回复
热议问题