6

I'm using fedora 22 and dnf-1.1.2-4.fc22.noarch

As an use-case scenario: I found that strace package is not installed. I want to figure out if this package belongs to any other group, to install software that I'll probably will need too for similar tasks.

I found this brute-force way(grepping for 3 spaces bacause group names start with this indent):

dnf grouplist | grep '   ' | while read line; do dnf groupinfo "$line"; done

Then redirect this output to a file, search for a package name, and find a group name there.

  • I downloaded the comps xml files and used several iterations of csplit to do something similar recently. Using an xslt tool would be better probably. I'm also interested to learn about a better way to do this. – Bram Oct 18 '15 at 9:30
3

Here's an example of something that seems to work in my fedora 21, but dnf is still changing, so try it and see:

$ pkg=fvwm
$ dnf groupinfo '*' | sed -n '/Group:/h;/'"$pkg"'/{x;p;x;p}'
Group: Window Managers
   fvwm

The sed holds (h) each group heading, and then when the package matches exchanges hold and pattern (x), prints the heading (p), exchanges back and prints the package.

  • Thank you. It is definetely better than mine. But why dnf doesn't have native command for this? – Alex Bozhenko Oct 19 '15 at 0:10
  • dnf is a redhat product, and work in progress. you could try submitting a request for enhancement to the redhat bugzilla list, but there are already over 1000 entries mostly marked NEW, so good luck with that. – meuh Oct 19 '15 at 8:47
  • 1 char shorter :) dnf groupinfo \* | sed -n '/Group:/h;/'"$pkg"'/{H;x;p}' just append the pattern space to the hold space, exchange and print. – Dani_l Nov 15 '16 at 5:34
  • 1
    I'm not using an english locale, and the output was erroneous, so better force the command with C locale as in: LC_ALL=C dnf groupinfo '*' | sed -n '/Group:/h;/'"$pkg"'/{x;p;x;p}' – Nelson Sep 14 '17 at 16:43
1

Another way using awk:

Package strace

pkg="strace"; dnf groupinfo '*' | awk -F": " '/^Group/ {group=$2} /'"$pkg"'/ {print group}'  

Output shows:

Security Lab
C Development Tools and Libraries

Package fvwm

pkg="fvwm"; dnf groupinfo '*' | awk -F": " '/^Group/ {group=$2} /'"$pkg"'/ {print group}'  

Output shows:

Window Managers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.