The output of yum deplist
looks like this:
$ yum deplist gtkd
...
dependency: librt.so.1()(64bit)
provider: glibc.x86_64 2.18-11.fc20
dependency: mesa-libGL
provider: mesa-libGL.x86_64 9.2-1.20130919.fc20
provider: mesa-libGL.i686 9.2-1.20130919.fc20
dependency: mesa-libGLU
provider: mesa-libGLU.x86_64 9.0.0-3.fc20
provider: mesa-libGLU.i686 9.0.0-3.fc20
...
Since the dependency line can give a library and not a package name, I would only keep the provider lines with grep provider
.
$ yum deplist gtkd | grep provider
...
provider: glibc.x86_64 2.18-11.fc20
provider: mesa-libGL.x86_64 9.2-1.20130919.fc20
provider: mesa-libGL.i686 9.2-1.20130919.fc20
provider: mesa-libGLU.x86_64 9.0.0-3.fc20
provider: mesa-libGLU.i686 9.0.0-3.fc20
...
Then I remove the string "provider:", the extra spaces before and after, and I keep the word just following using sed "s/[ ]*provider:[ ]*\([^ ]*\).*/\1/"
for example:
$ yum deplist gtkd | grep provider | sed "s/[ ]*provider:[ ]*\([^ ]*\).*/\1/"
...
glibc.x86_64
mesa-libGL.x86_64
mesa-libGL.i686
mesa-libGLU.x86
mesa-libGLU.i686
...
I can now keep everything before the last period with sed "s/\(.*\)\.[^\.]*/\1/"
:
$ yum deplist gtkd | grep provider | sed "s/[ ]*provider:[ ]*\([^ ]*\).*/\1/" | sed "s/\(.*\)\.[^\.]*/\1/"
...
glibc
mesa-libGL
mesa-libGL
mesa-libGLU
mesa-libGLU
...
And I sort as you do removing the duplicates with sort -u
:
$ yum deplist gtkd | grep provider | sed "s/[ ]*provider:[ ]*\([^ ]*\).*/\1/" | sed "s/\(.*\)\.[^\.]*/\1/" | sort -u
atk
cairo
gdk-pixbuf2
glibc
gstreamer
gstreamer-plugins-base
gtk2
gtksourceview2
libglade2
mesa-libGL
mesa-libGLU
pango
Edit: I have updated the answer according to @marcindulak remark, so it can now work with dependencies whose name contains a dot:
$ yum deplist icedtea-web | grep provider | sed "s/[ ]*provider:[ ]*\([^ ]*\).*/\1/" | sed "s/\(.*\)\.[^\.]*/\1/" | sort -u
bash
chkconfig
glib2
glibc
java-1.7.0-openjdk
libgcc
libstdc++
mozilla-filesystem
You might also enjoy
repoquery
, if you aren't already aquainted. Depending on your purpose, you don't even need to parse out package names -yum install libphobos-ldc.so.60
will work just fine.