How do I parse the output of "dnf provides"?

It appears to not be designed to be parsed machinally, but this is not problematic, because what I want is consistently placed:

[root@1656943212 BEEDELLROKEJULIANLOCKHART]# dnf provides spotify
Last metadata expiration check: 0:42:44 ago on Mon 18 Jul 2022 23:56:32 BST.
spotify-client-1.1.84.716-1.fc36.x86_64 : Spotify music player native client
Repo        : @System
Matched from:
Provide    : spotify = 1.1.84.716-1.fc36

I want the package-name, which is “spotify-client-1.1.84.716-1.fc36.x86_64”. How might I ascertain what regex or tool to utilize to cut everything from the 2nd line to the colon?

You could use awk if you want to parse it that way.

2 Likes

Or use dnf repoquery, which is very versatile DNF Command Reference — dnf latest documentation
dnf repoquery --whatprovides spotify --nvr
or use --qf to get exactly what you want:
dnf repoquery --whatprovides spotify --qf "%{name}-%{version}-%{release}.%{arch}"

4 Likes

Indeed, but are you able to more specifically explain how to? My previous attempts have been unsuccessful.

Weirdly,

[BEEDELLROKEJULIANLOCKHART@1656943212 ~]$ dnf provides spotify
Last metadata expiration check: 0:01:47 ago on Tue 19 Jul 2022 12:48:56 BST.
spotify-client-1.1.84.716-1.fc36.x86_64 : Spotify music player native client
Repo        : @System
Matched from:
Provide    : spotify = 1.1.84.716-1.fc36

[BEEDELLROKEJULIANLOCKHART@1656943212 ~]$ dnf repoquery --whatprovides spotify
Last metadata expiration check: 0:02:16 ago on Tue 19 Jul 2022 12:48:56 BST.
[BEEDELLROKEJULIANLOCKHART@1656943212 ~]$

demonstrates that “dnf provides spotify” provides the name of the package, whereas “dnf repoquery --whatprovides spotify” does not.

Additionally,

PS /home/BEEDELLROKEJULIANLOCKHART> dnf repoquery --whatprovides spotify
Last metadata expiration check: 0:40:22 ago on Tue 19 Jul 2022 13:34:44 BST.
PS /home/BEEDELLROKEJULIANLOCKHART> dnf repoquery --whatprovides vlc    
Last metadata expiration check: 0:40:29 ago on Tue 19 Jul 2022 13:34:44 BST.
vlc-1:3.0.17.2-1.fc36.x86_64
vlc-1:3.0.17.4-1.fc36.x86_64
PS /home/BEEDELLROKEJULIANLOCKHART> dnf repoquery --whatprovides vlc --qf "%{name}-%{version}-%{release}.%{arch}"    
Last metadata expiration check: 0:40:41 ago on Tue 19 Jul 2022 13:34:44 BST.
vlc-3.0.17.2-1.fc36.x86_64
vlc-3.0.17.4-1.fc36.x86_64

demonstrates that dnf appears to ignore the custom format specified.

Can you try:

dnf provides spotify | awk 'FNR==2 {print $1}'

I should point out that parsing this dnf output feels somewhat fragile.

1 Like

Use CLI tool => dnf list grep what you want surrounded with asterisks as wildcard. No natif package, you must download and install spotify-client.rpm, search on the web as exists.

This is completely different than what the OP is trying to accomplish. Package names that contain a string are not the same as provides.

As an example, compare the output of these two commands

dnf provides awk

with:

dnf list "*awk*"
1 Like

Spotify is a proprietary music streaming service, awk a standard GNU CLI command … ? You simply open a browser to use Spotify.

Since the OP was asking for a scripting solution, presumably spotify was just an example. This topic isn’t about, “How do I use spotify?”

1 Like

Irrelevant, because Spotify provides a local client, too. The example utilized is irrelevant anyway, because I am able to want the name of the package that provides pkcon, for instance.

However, I am thankful for your assistance.

1 Like

If you query for spotify* or spotify-client you’ll probably get results with dnf repoquery for spotify.
Now I see that the docs states that

`<package-file-spec>` is similar to `<package-spec>`, except provides matching is not performed. Therefore, `<package-file-spec>` is matched only against NEVRAs and file provides.

and dnf matches by <package-spec> while dnf repoquery by <package-file-spec> (which doesn’t check what package states to provide). So it’s not a bug, I just didn’t know that before.

Where?

%{name} -   %{version}  -   %{release}  .   %{arch}
vlc     -   3.0.17.4    -   1.fc36      .   x86_64

Default repoquery output also checks out:

--nevra
    Show found packages in the name-epoch:version-release.architecture format. Same as --qf "%{name}-%{epoch}:%{version}-%{release}.%{arch}" (default).

On a side note, since spotify is proprietary, It seems safer to use it through sandbox, like flatpak: Spotify | Flathub

1 Like

OK … in a terminal type ‘man dnf’ … all information about keyword ‘provides’ is explained concisely near the bottom of the page in subsection ‘Provides Command’', very few lines of text. Goodbye …

@marko23, why? I’m receiving very useful assistance from @ozeszty and @dalto. Did you ever intend to assist?

My ultimate solution has been pwsh -c "pkcon -p what-provides $value|Select-String 'Available','Installed'|awk '{print $2}'", but I have been unable to ascertain why dnf repoquery --whatprovides $value and pkcon what-provides $value are unable to state what provides obs and spotify.

That didn’t work?

for spotify at least, the rpm package you’re looking for is
lpf-spotify-client

so to match you would need something like: *spotify*client for provides or for repo query. That particular package installs via lpf the spotify-client. GitHub - rpmfusion/lpf-spotify-client: lpf-spotify-client - nonfree

DNF assumes that the <provide-spec> is a system command, prepends it with /usr/bin/, /usr/sbin/ prefixes (one at a time) and does the file provides search again. For legacy reasons (packages that didn’t do UsrMove) also /bin and /sbin prefixes are being searched

so for another example:
dnf provides firefox
or
dnf rq --whatprovides firefox

both work

but
dnf provides firefox-bin
or
dnf rq --whatprovides firefox-bin

does not unless you specify the path (/usr/lib64/firefox/firefox-bin) or use additional wildcards.

like, sudo dnf provides *firefox-bin

1 Like