Frank Szczerba on 24 May 2013 05:44:35 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] 2013-05-21 PLUG W follow-up


If you want to align left within the fields (spaces on the right) use a specifier like "%-15s".

I'd just size the count column to the largest reasonable value one could expect to see.

Of course, there's nothing wrong at all about using column for this either, unless perhaps your output is potentially huge, in which case column has to buffer all of the content before it can generate output, while the printf approach just formats it as you go.

Frank

On May 23, 2013, at 10:51 PM, Bill East <wm.east@gmail.com> wrote:

On Thu, May 23, 2013 at 10:00 AM, Frank Szczerba <frank@szczerba.net> wrote:
You could use field width specifies in the printf:

printf "%3d   %15s   %s\n" 4 10.11.12.13 dns.name.one
printf "%3d   %15s   %s\n" 2  207.111.106.151 yet.another.name

outputs

  4       10.11.12.13   dns.name.one
  2   207.111.106.151   yet.another.name

but column -t is pretty nice too.

That was nice. I had to make things more complex for myself so I pulled the length of the first (highest, because of sort -r) left variable and used that (+1) to define the first column's width so that if it exceeded 999 hits it wouldn't cause problems. Looking at the output in the end, the field width specifiers padded whitespace to the left of the variables, column -t padded right. So then it pretty much comes down to which you like better.

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug