Saya mencoba memproses informasi jaringan dari lshw -c network
dengan perintah awk
hasilnya terlihat seperti ini: -
*-network:3
description: Ethernet interface
product: I350 Gigabit Network Connection
vendor: Intel Corporation
physical id: 0.3
bus info: pci@0000:03:00.3
logical name: eth1
version: 01
serial: xx:xx:xx:xx:xx:xx
size: 1GB/s
capacity: 1GB/s
width: 32 bits
clock: 33MHz
*-network
description: Ethernet interface
physical id: 1
logical name: eth0
serial: yy:yy:yy:yy:yy:yy
capabilities: ethernet physical
configuration: broadcast=yes driver=vif link=yes multicast=yes
Saya ingin mencetak ini dalam format tabel tetapi hanya jika blok berisi bus info:
, di sini hanya blok pertama yang memenuhi syarat dan akan dicetak dalam format
hasil akhir:-
description product vendor physical id bus info ...
Ethernet.. I350 G.. Intel.. 0.3 pci@0000:03:00.3
upaya terbaik saya adalah: -
lshw -c network |
awk -v FS=:
$0 ~ /*-network.*/ {
v1 = NR;
v2 = "";
v3 = 0
}
NR > v1 && v3 == 0 {
v2 = v2"@"$3
}
$1 ~ /bus info.*/ {
v3 = 1
}
v3 == 1 {
split(v2, ar, "@");
for (t in ar) { print t};
print $1
}
tanpa hasil