Date: Sun, 14 Jul 2019 12:57:32 +0200 From: Andreas Perstinger <andipersti@gmail.com> To: freebsd-questions@freebsd.org Subject: Re: pkg query timestamp format Message-ID: <c654c974-4226-f07c-a74a-d02574351cb2@gmail.com> In-Reply-To: <5343D197-AF3A-490E-AB75-F0624A77A3FE@kreme.com> References: <5D28CD7B.40102@webtent.org> <e2771f34-b0fe-5c09-dc8b-b2d549fdacbf@holgerdanske.com> <5343D197-AF3A-490E-AB75-F0624A77A3FE@kreme.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 13.07.19 11:31, @lbutlr wrote: >> On 12 Jul 2019, at 18:30, David Christensen <dpchrist@holgerdanske.com> wrote: >> Here's a Perl one-liner: >> >> 2019-07-12 17:28:52 dpchrist@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?c654c974-4226-f07c-a74a-d02574351cb2>