pkg query timestamp format

@lbutlr kremels at kreme.com
Sun Jul 14 09:18:00 UTC 2019


On 13 Jul 2019, at 12:22, Polytropon <freebsd at edvax.de> wrote:
> On Sat, 13 Jul 2019 03:31:17 -0600, @lbutlr wrote:
>> On 12 Jul 2019, at 18:30, David Christensen <dpchrist at holgerdanske.com> wrote:
>>> $ pkg query %n-%t | perl -ne '/(.+)-(\d+)$/; ($d,$m,$y)=(localtime $2)[3,4,5];$y+=1900; printf "%-50s %4i-%02i-%02i\n", $1, $y, $m ,$d’

>> I tried to add a | sort -k 2, thinking that would sort the output
>> by date, but while it changed the order of the output (no other
>> number did), it wasn’t based on the date column. Not sure what
>> it was based on.
>> 
>> I also tried -k 2,4 and -k 2 -k 3
>> 
>> I assume I am missing something bloody obvious.
> 
> In the formatting rule of the perl printf command, put a
> delimiter, for example "/": "%-50s/%4i-%02i-%02i\n", then
> use "| sort -t '/' +1" or "| sort -g -t '/' +1". ISO dates
> are sortable by definition. This should sort by the _2nd_
> column with the defined delimiter.

Sure, but -k should pick up on white space, I thought.

> Or, probably much easier, change the printf command to
> create output as "<date> <package>" instead of the example
> providing "<package> <date>", and just send this to "| sort”.

This is what I did, in fact, but I was (and am) confused why sort -k 2 didn’t work on the original output.



-- 
Some people are like a Slinky toy - not really good for anything, but
you still can't help but smile when you shove them down the stairs.



More information about the freebsd-questions mailing list