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 8256911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:01:29+00:00 2026-06-08T02:01:29+00:00

I’m new to bash and want to improve. I need to learn reading specific

  • 0

I’m new to bash and want to improve. I need to learn reading specific text from a file or from output of a command.For example I want to sum of the total ethernet interrupt numbers of each core of the computer from /proc/interrupts file.The content of the file is:

CPU0       CPU1       CPU2       CPU3
0:        142          0          0          0   IO-APIC-edge      timer
1:          1          0          1          0   IO-APIC-edge      i8042
4:        694         18        635         19   IO-APIC-edge      serial
7:          0          0          0          0   IO-APIC-edge      parport0
9:          0          0          0          0   IO-APIC-fasteoi   acpi
12:          1          1          0          2   IO-APIC-edge      i8042
14:          0          0          0          0   IO-APIC-edge      ide0
19:          0          0          0          0   IO-APIC-fasteoi   uhci_hcd:usb3
23:          0          0          0          0   IO-APIC-fasteoi   ehci_hcd:usb1,  uhci_hcd:usb2
46:     347470     119806     340499     108227   PCI-MSI-edge      ahci
47:      33568      45958      46028      49191   PCI-MSI-edge      eth0-rx-0
48:          0          0          0          0   PCI-MSI-edge      eth0-tx-0
49:          1          0          1          0   PCI-MSI-edge      eth0
50:      28217      42237      65203      39086   PCI-MSI-edge      eth1-rx-0
51:          0          0          0          0   PCI-MSI-edge      eth1-tx-0
52:          0          1          0          1   PCI-MSI-edge      eth1
59:     114991     338765      77952     134850   PCI-MSI-edge      eth4-rx-0
60:     429029     315813     710091      26714   PCI-MSI-edge      eth4-tx-0
61:          5          2          1          5   PCI-MSI-edge      eth4
62:    1647083     208840    1164288     933967   PCI-MSI-edge      eth5-rx-0
63:     673787    1542662     195326    1329903   PCI-MSI-edge      eth5-tx-0
64:          5          6          7          4   PCI-MSI-edge      eth5

I need to read all of the numbers of interrupts with “eth” keyword and then find the sum of them for each CPU core(whateve the CPU core name is). For example for CPU0:33568+0+1+28217…
What is suitable for this? Must I use awk or sed for regex and how?

  • 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-06-08T02:01:30+00:00Added an answer on June 8, 2026 at 2:01 am

    You could use awk for this, there is no need for grep or any other tool since awk can do the search itself.

    UPDATE:

    Based on the possibility of varying number of CPU columns (see first comment below), this will work:

    NR==1 {
      core_count = NF
      print "core count: ", core_count
      next
    }
    /eth/ {
      for (i = 2; i <= 2+core_count; i++)
        totals[i-2] += $i
    }
    
    END {
      print "Totals"
      for (i = 0; i < core_count; i++)
        printf("CPU%d: %d\n", i, totals[i])
    }
    

    gives output:

    core count:  4
    Totals
    CPU0:  2926686
    CPU1:  2494284
    CPU2:  2258897
    CPU3:  2513721
    

    Notes:

    If the first line only contains CPU headers, then using NF as shown at the start of the script will work. If other data might be present then core_count = gsub(/CPU/, "CPU") could be used. Also, this script depends on consecutive CPU columns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a text area in my form which accepts all possible characters from
i want to parse a xhtml file and display in UITableView. what is the
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.