Date: Sat, 13 Jul 2019 13:39:49 -0700 From: David Christensen <dpchrist@holgerdanske.com> To: freebsd-questions@freebsd.org Subject: Re: pkg query timestamp format Message-ID: <960ddbaa-7a6a-c387-0e63-6f247e6dbf10@holgerdanske.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 7/13/19 2:31 AM, @lbutlr wrote: > > >> On 12 Jul 2019, at 18:30, David Christensen <dpchrist@holgerdanske.com> wrote: >> >> On 7/12/19 11:12 AM, Robert Fitzpatrick via freebsd-questions wrote: >>> When I use the following command, I get packages with timestamp installed in epoch Unix time. Is there any way to format that date into month, day and year? >>> pkg query %n-%t >> >> 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. There is no need for a pipeline and sort(1): 2019-07-13 13:16:07 dpchrist@cvs ~ $ pkg query %n-%t | perl -e 'while(<>){/(.+)-(\d+)$/;($d,$m,$y)=(localtime $2)[3,4,5];$h{sprintf "%-50s",$1}=sprintf "%4i-%02i-%02i",$y+1900,$m,$d} print map {$_,$h{$_},"\n"} sort {"$h{$a} $a" cmp "$h{$b} $b"} keys %h' bash 2019-01-21 cvs 2019-01-21 gettext-runtime 2019-01-21 <snip> p5-UNIVERSAL-require 2019-03-19 rename 2019-04-09 pkg 2019-06-12 David
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?960ddbaa-7a6a-c387-0e63-6f247e6dbf10>