Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Aug 2019 12:38:02 -0700
From:      "J.B." <non.euc.geo.1854@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: pkg query timestamp format
Message-ID:  <34e81f2a-83c5-6de8-a220-42aa9b9f1e7a@gmail.com>
In-Reply-To: <mailman.75.1563019202.39642.freebsd-questions@freebsd.org>
References:  <mailman.75.1563019202.39642.freebsd-questions@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 7/13/19 5:00 AM, freebsd-questions-request@freebsd.org 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
> Judging from "man pkg-query", the %t information (timestamp
> of installation) cannot be changed into a different format.
>
> But according to "man date" and "man strftime", there is a
> solution, which is only_half_  a solution because my script
> foo fails to provide a way to keep the package name, but hey,
> the dates_can_  be converted.
>
> 	pkg query %n/%t | cut -d '/' -f 2 | xargs -n 1 -J @ date -j -f "%s" @ "+%Y-%m-%d_%H:%M:%S"
>
> I didn't find a way to feed one information of the $n/%t
> pair unaltered and uninterpreted (!) into date, but the
> conversion of the date Epoch -> YYYY-MM-DD_HH:MM:SS works.
> With an enclosing script it would probably be much easier,
> but at the moment, I can only provide this one-liner as an
> inspiration for further coding...:-)

Here's a modified version of your solution in awk:

    # pkg query %n/%t | awk '{ print $1 } { system("date -j -f \"%s\" "
    $NF " \"+%Y-%m-%d_%H:%M:%S\"") }' FS=\/ ORS=\\t
    xterm   2019-08-16_10:32:13
    xvid    2018-12-25_00:19:03
    xvinfo  2019-04-20_12:29:07




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?34e81f2a-83c5-6de8-a220-42aa9b9f1e7a>