0

I want to take the number of bytes transmitted and received from /proc/net/dev in this format: num_ofbytesTransmitted,num_ofbytesReceived. This was my approach:

cat /net/proc/dev | grep enp0s3 | cut -f5 -d' '

and

cat /net/proc/dev | grep enp0s3 | cut -f48 -d' '

but the problem here is that I can't always use these constants on cut since the numbers can get big and that number has to change... What can I do in these circumstances?

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
C. Cristi
  • 228
  • 3
  • 13

1 Answers1

1

Use AWK instead:

awk -v OFS=, '/enp0s3:/ { print $10, $2 }' /proc/net/dev

This looks for lines matching “enp0s3:” in /proc/net/dev, and prints the tenth and second fields, separated by a comma.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164