Re: a question regarding proper printf(3) formating and alignment
In the last episode (Nov 17), Karl Vogel said: > >> In the last episode (Nov 17), Alexander Best said: > > A> i've looked at a lot of utilities in the bsd src tree and most of them > A> seem to be doing something like this: > > A> Device 1M-blocks UsedAvail Capacity > A> /dev/label/swapfs 10239010239 0% > A> /dev/label/swap 81910 8191 0% > A> Total 18431018431 0% > > A> i'd like to learn of ways formatting the header so that it aligns > A> properly, whether the device name is 10 chars long or 1000. > >ports/textproc/align is a nifty perl script that'll do this for just >about any type of column-based input. If you just want to fix "df" and >you know how long the longest device name is, try something like this: Bad example, since df also auto-sizes its columns :) I think /usr/bin/rs can do column auto-balancing, but every time I try to make it do what I want, I fail. -- Dan Nelson dnel...@allantgroup.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: a question regarding proper printf(3) formating and alignment
>> In the last episode (Nov 17), Alexander Best said: A> i've looked at a lot of utilities in the bsd src tree and most of them A> seem to be doing something like this: A> Device 1M-blocks UsedAvail Capacity A> /dev/label/swapfs 10239010239 0% A> /dev/label/swap 81910 8191 0% A> Total 18431018431 0% A> i'd like to learn of ways formatting the header so that it aligns A> properly, whether the device name is 10 chars long or 1000. ports/textproc/align is a nifty perl script that'll do this for just about any type of column-based input. If you just want to fix "df" and you know how long the longest device name is, try something like this: #!/bin/ksh #> On Wed, 17 Nov 2010 13:55:21 -0600, >> Dan Nelson happily babbled in reply: D> I seem to remember /usr/bin/find doing this dynamically by expanding D> columns as it saw values that were larger than the previous max, but D> apparently not (I just tested it). I believe you're thinking of "file". -- Karl Vogel I don't speak for the USAF or my company When a man says it's a silly, childish game, it's probably something his wife can beat him at. --Epperson's law ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: a question regarding proper printf(3) formating and alignment
On Wed Nov 17 10, Dan Nelson wrote: > In the last episode (Nov 17), Alexander Best said: > > hi there, > > > > i've looked at a lot of utilities in the bsd src tree and most of them > > seem to be doing something like this: > > > > Device 1M-blocks UsedAvail Capacity > > /dev/label/swapfs 10239010239 0% > > /dev/label/swap 81910 8191 0% > > Total 18431018431 0% > > > > as you can see the header simply gets written with a number of tabs in > > between the keywords, but then the actual output aligns differently. > > > > i'd like to learn of ways formatting the header so that it aligns > > properly, whether the device name is 10 chars long or 1000. is there an > > example for this somewhere in the src tree? > > /bin/ls does this for the user, group, and size columns. Note that this > only works if you batch up your output (or take two passes over your input > data). I seem to remember /usr/bin/find doing this dynamically by expanding > columns as it saw values that were larger than the previous max, but > apparently not (I just tested it). thanks. so looking at the /bin/ls source is probably the first i should do. cheers. alex > > -- > Dan Nelson > dnel...@allantgroup.com -- a13x ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: a question regarding proper printf(3) formating and alignment
In the last episode (Nov 17), Alexander Best said: > hi there, > > i've looked at a lot of utilities in the bsd src tree and most of them > seem to be doing something like this: > > Device 1M-blocks UsedAvail Capacity > /dev/label/swapfs 10239010239 0% > /dev/label/swap 81910 8191 0% > Total 18431018431 0% > > as you can see the header simply gets written with a number of tabs in > between the keywords, but then the actual output aligns differently. > > i'd like to learn of ways formatting the header so that it aligns > properly, whether the device name is 10 chars long or 1000. is there an > example for this somewhere in the src tree? /bin/ls does this for the user, group, and size columns. Note that this only works if you batch up your output (or take two passes over your input data). I seem to remember /usr/bin/find doing this dynamically by expanding columns as it saw values that were larger than the previous max, but apparently not (I just tested it). -- Dan Nelson dnel...@allantgroup.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"