Subject: Re: nightly report "network" section.
To: NetBSD Userlevel Technical Discussion List <tech-userlevel@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-userlevel
Date: 12/07/2003 16:07:52
> How about using awk instead, [with explicit printf field widths to
> spread things out in case numbers are wider than their fields]
> Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Colls
> de0 1500 <Link> 00:00:c0:83:c3:e9 232673148 0 273729698 4 0
> On that system the above script produces the much more readable:
> Name Ipkts Ierrs Opkts Oerrs Colls
> de0 232673278 0 273729835 4 0
> lo0 39483013 0 39483013 0 0
In case anyone cares, I long ago wrote a program designed specifically
to neaten up such output. I called it halign, after TeX's \halign
operation. For example...
% cat in
Name Ipkts Ierrs Opkts Oerrs Colls
de0 232673278 0 273729835 4 0
lo0 39483013 0 39483013 0 0
% halign l -m r < in
Name Ipkts Ierrs Opkts Oerrs Colls
de0 232673278 0 273729835 4 0
lo0 39483013 0 39483013 0 0
% halign l8 r10 r6 r10 r6 r6 < in
Name Ipkts Ierrs Opkts Oerrs Colls
de0 232673278 0 273729835 4 0
lo0 39483013 0 39483013 0 0
%
(the last halign specifies explicit minimum column widths matching the
printf format in the awk script given; unlike the awk script, if any of
the fields are too wide for the widths, that whole column will be
widened, rather than just that line).
The whole thing could be done with halign, actually, except that
netstat sometimes leaves the "Address" field completely blank. If I
edit out the blank-address lines....
% cat in
Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Colls
le0 1500 <Link> 08:00:20:86:9a:35 3557815 1 3324719 0 24115
le0 1500 216.46.5/28 216.46.5.7 3557815 1 3324719 0 24115
le0 1500 fe80::/64 fe80::a00:20ff:fe 3557815 1 3324719 0 24115
le0 1500 10.0.2/24 10.0.2.7 3557815 1 3324719 0 24115
le0 1500 3ffe:b00:4020 3ffe:b00:4020:300 3557815 1 3324719 0 24115
lo0 32976 fe80::/64 fe80::1 54941043 0 54941043 0 0
lo0 32976 ::1/128 ::1 54941043 0 54941043 0 0
lo0 32976 127 127.0.0.1 54941043 0 54941043 0 0
% halign l8 x x x r10 r6 r10 r6 r6 < in | uniq
Name Ipkts Ierrs Opkts Oerrs Colls
le0 3557815 1 3324719 0 24115
lo0 54941043 0 54941043 0 0
%
So if you want to hack on netstat, you can just make the "Address"
field always nonblank (and pick up halign :-).
halign can be fetched by anonymous ftp from one of my house machines,
216.46.5.7, under /mouse/local/src/,
halign/halign-20020121/halign.{1,c} in particular.
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B