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' '


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?

  • Quick tip: Drop cat and do grep enp0s3 /net/proc/dev instead. – forest Nov 21 '18 at 7:06
  • @forest are you sure it's just that? – C. Cristi Nov 21 '18 at 7:10
  • No, that's why it was a quick tip instead of an answer. – forest Nov 21 '18 at 7:12
  • @forest I understand but I have no clue how to use your tip – C. Cristi Nov 21 '18 at 7:16
  • Same homework over on AU: askubuntu.com/questions/1094459/… – muru Nov 21 '18 at 7:40

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.