[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#961411: apt search -- output NOT grepable



On Sun, May 24, 2020 at 12:49:21PM -0400, Lee wrote:
> On 5/24/20, Leszek Dubiel <leszek.dubiel@dubielvitrum.pl> wrote:
> > I've completely switched to using "apt" for all debian package management.
> > I'm fine with the "apt" tool, it fits all my needs except one... serarching.

It's no problem to use "apt-cache search" if you prefer that. apt-cache
and friends aren't going away and if they do what you like, use them!
I don't know where this notion that they shouldn't be used anymore
is coming from. If only people would do that with tools which really are
not to be used (looking at you apt-key…).

The same people are maintaining them all and so if you peak under the
lid you would notice that it tends to be even the very same code just
with an option here or there flipping a default… so, without promising
any backward compatibility:
$ apt search perl -o APT::Cache::Search::Version=1

If you want to set this in a config file use:
Binary::apt::APT::Cache::Search::Version "1";


As said, no promise that this will work forever. The various things
Julian hints at might be better choices in the future.


> $ apt search perl | awk -v RS="" '{gsub("\n",""); print $0}' | grep JSON | grep -i data

awk is certainly powerful, but at least I can never type out such
commands without a least one trip to the manpage, websearch or
frantically grepping in my shell history files…

So I tend to prefer combinations of far less powerful tools.
I like `cut` and it has an even less known sibling with `paste`:

apt search -qq perl | paste -d' ' - - - | …

`-qq` disables the progress reporting in apt which is two lines which
would confuse the rest. `paste` takes three lines from stdin (`-`) and
separates them each with a space (`-d' '`).

One day I will learn awk – if cut and paste fail me 😉


Best regards

David Kalnischkies

Attachment: signature.asc
Description: PGP signature


Reply to: