Note that there are some explanatory texts on larger screens.

plurals
  1. POcounting interface types with awk
    primarykey
    data
    text
    <p>I've got the following input:</p> <pre><code>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) </code></pre> <p>This is from <code>lspci</code> 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.</p> <p>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:</p> <pre><code>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) </code></pre> <p>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 <code>lspci -v</code> output from other systems, hence the extra <code>'/Eth|Net/{if ($2 ~ /^Eth|^Net/) print}'</code> logic to ensure I get the right thing.</p> <pre><code>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 &lt;=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}' </code></pre> <p>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.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload