Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 274281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:35:09+00:00 2026-05-12T00:35:09+00:00

The output of /proc/net/dev on Linux looks like this: Inter-| Receive | Transmit face

  • 0

The output of /proc/net/dev on Linux looks like this:

Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:18748525  129811    0    0    0     0          0         0 18748525  129811    0    0    0     0       0          0
  eth0:1699369069 226296437    0    0    0     0          0      3555 4118745424 194001149    0    0    0     0       0          0
  eth1:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
  sit0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

How can I use Python to parse this output into key:value pairs for each interface? I have found this forum topic for achieving it using shell scripting and there is a Perl extension but I need to use Python.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:35:09+00:00Added an answer on May 12, 2026 at 12:35 am

    this is pretty formatted input and you can easily get columns and data list by splitting each line, and then create a dict of of it.

    here is a simple script without regex

    lines = open("/proc/net/dev", "r").readlines()
    
    columnLine = lines[1]
    _, receiveCols , transmitCols = columnLine.split("|")
    receiveCols = map(lambda a:"recv_"+a, receiveCols.split())
    transmitCols = map(lambda a:"trans_"+a, transmitCols.split())
    
    cols = receiveCols+transmitCols
    
    faces = {}
    for line in lines[2:]:
        if line.find(":") < 0: continue
        face, data = line.split(":")
        faceData = dict(zip(cols, data.split()))
        faces[face] = faceData
    
    import pprint
    pprint.pprint(faces)
    

    it outputs

    {'    lo': {'recv_bytes': '7056295',
                'recv_compressed': '0',
                'recv_drop': '0',
                'recv_errs': '0',
                'recv_fifo': '0',
                'recv_frame': '0',
                'recv_multicast': '0',
                'recv_packets': '12148',
                'trans_bytes': '7056295',
                'trans_carrier': '0',
                'trans_colls': '0',
                'trans_compressed': '0',
                'trans_drop': '0',
                'trans_errs': '0',
                'trans_fifo': '0',
                'trans_packets': '12148'},
     '  eth0': {'recv_bytes': '34084530',
                'recv_compressed': '0',
                'recv_drop': '0',
                'recv_errs': '0',
                'recv_fifo': '0',
                'recv_frame': '0',
                'recv_multicast': '0',
                'recv_packets': '30599',
                'trans_bytes': '6170441',
                'trans_carrier': '0',
                'trans_colls': '0',
                'trans_compressed': '0',
                'trans_drop': '0',
                'trans_errs': '0',
                'trans_fifo': '0',
                'trans_packets': '32377'}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am calling a SQL proc that has 3 OUTPUT params. After the call
I got this output when running sudo cpan Scalar::Util::Numeric jmm@freekbox:~/bfwsandbox/sa/angel/astroportal/dtu8e/resources$ sudo cpan Scalar::Util::Numeric [sudo]
Is it possible to capture print output from a T-SQL stored procedure in .NET?
You'd like to call a stored proc on MS SQL that has a parameter
I'm calling a .net webservice from Linux using Perl (5.8.7). I'm using the SOAP::Lite
(please excuse that I didn't use aliases). I would like my query output to
PROC FCMP requires a three-level argument when specifying the output dataset in which the
Is output buffering enabled by default in Python's interpreter for sys.stdout ? If the
The output we get when printing C++ sources from Eclipse is rather ugly. Is
The output of my JSON call can either be an Array or a Hash.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.