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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:48:40+00:00 2026-06-07T08:48:40+00:00

I’ve got the following input: 03:00.0 Ethernet controller: Broadcom Corporation NetBooty BCM5111 Gigabit Ethernet

  • 0

I’ve got the following input:

03:00.0 Ethernet controller: Broadcom Corporation NetBooty BCM5111 Gigabit Ethernet (rev 59)
03:00.1 Ethernet controller: Broadcom Corporation NetBooty BCM5111 Gigabit Ethernet (rev 59)
03:00.2 Ethernet controller: Broadcom Corporation NetBooty BCM5111 Gigabit Ethernet (rev 59)
03:00.3 Ethernet controller: Broadcom Corporation NetBooty BCM5111 Gigabit Ethernet (rev 59)
04:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
04:00.1 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
05:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
05:00.1 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
06:00.0 Network controller: Intel Corporation Centrino Ultimate-N 6300 (rev 3e)                                                                                                    

This is from lspci in linux and it obviously shows ethernet/wireless devices and their corresponding pci ids. In this case, the output shows me that the system has 1 quad-port BCM690 nic (I made that up), 2 dual-port BCM5709, and an Intel 6300 wifi controller.

I’m trying to write awk logic that could handle that (and much more verbose output on more interface-ful systems), printing a succinct summary. Proposed output format, given above input:

4 Broadcom Corporation NetBooty BCM5111 Gigabit Ethernet (rev 59) {1x4-port}
4 Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20) {2x2-port}  
1 Intel Corporation Centrino Ultimate-N 6300 (rev 3e)

With my limited awk knowledge I’ve so far been only marginally successful. Following this is what I’ve got, but note I often review files containing lspci -v output from other systems, hence the extra '/Eth|Net/{if ($2 ~ /^Eth|^Net/) print}' logic to ensure I get the right thing.

awk '/Eth|Net/{if ($2 ~ /^Eth|^Net/) print}' lspci.txt |
awk -F: '{if ($2 ~ /^...0/) pci[$1$2]=$3; count[$3]++} END {for (i in pci) printf "%s %s\n", count[pci[i]], pci[i]}' |
uniq -c |
awk '{nic=""; for (i=3; i <=NF; i++) nic = nic $i " "; if ($1 == 1) printf "%s %s\n", $2, nic; if ($1 != 1) printf "%s %s {%dx%d-port}\n", $2, nic, $1, $2/$1}'

This produces the desired output, mostly, but uh… I’d love to get that down to a single awk command. Any feedback appreciated. Examples are even better. I don’t need the answer spelled out; I just need to be pointed to some examples of similar things. (If you’ve got a better tool for the job than awk, point me towards that too please.)

  • 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-07T08:48:42+00:00Added an answer on June 7, 2026 at 8:48 am
    awk '{$1 = ""; sub(" ", ""); arr[$0]++} END {for (i in arr) {print arr[i], i}}' 
    

    Throw away the first field and the first field delimiter. Use the rest of the line as an index into a counter array. At the end print the count and the index.

    Here is a version that prints the port count (split out on multiple lines):

    awk '
        {
            split($1, slot, ":");
            $1 = "";
            sub(" ", ""); 
            split($0, type, ":");
            iface[type[2]]++;
            if (!(slot[1] SUBSEP type[2] in slots)) {
                slots[slot[1], type[2]];
                slotcount[type[2]]++
            }
        }
        END {
            for (ifacetype in iface) {
                slotc = slotcount[ifacetype];
                typec = iface[ifacetype]
                ports = "";
                if (typec > 1) {
                    ports = " {" slotc "x" typec/slotc "-port}"
                };
                print typec, ifacetype, ports
            }
        }'
    

    Save the slot information in an array. Discard the first field and the first delimiter. Count the interfaces. If we haven’t seen the slot before, remember it (simply referring to an array element creates it). Count the slots for that interface type.

    For each interface type, get the slot count and the count for that type. Print the information. The number of ports per interface is the count of a type divided by slots occupied by that type of interface.

    By the way, this double test:

    '/Eth|Net/{if ($2 ~ /^Eth|^Net/) print}'
    

    can be simplified to:

    '$2 ~ /^Eth|^Net/ {print}'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I need to clean up various Word 'smart' characters in user input, including but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.