pkg query timestamp format
Andreas Perstinger
andipersti at gmail.com
Sun Jul 14 10:57:37 UTC 2019
On 13.07.19 11:31, @lbutlr wrote:
>> On 12 Jul 2019, at 18:30, David Christensen <dpchrist at holgerdanske.com> wrote:
>> Here's a Perl one-liner:
>>
>> 2019-07-12 17:28:52 dpchrist at cvs ~
>> $ 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'
>> bash 2019-01-21
>> cvs 2019-01-21
>> gettext-runtime 2019-01-21
>> <snip>
>
> 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.
TL;DR use sort -b -k 2
From man sort:
"A field is defined as a maximal sequence of characters other than the
field separator and record separator (newline by default). Initial
blank spaces are included in the field unless -b has been specified; the
first blank space of a sequence of blank spaces acts as the field
separator and is included in the field (unless -t is specified). For
example, all blank spaces at the beginning of a line are considered to
be part of the first field."
So you should notice that packages with short names are listed first
because there are more blank spaces in front of the dates. Only when
package names have the equal number of letters the dates get sorted as
you expected.
Bye, Andreas
More information about the freebsd-questions
mailing list