I am using dnf list installed to list all installed packages, which returns the following output:

zenity.x86_64                                                                         3.22.0-1.fc25                                                               @@commandline          
zip.x86_64                                                                            3.0-16.fc24                                                                 @@commandline          
zlib.i686                                                                             1.2.8-10.fc24                                                               @@commandline          
zlib.x86_64                                                                           1.2.8-10.fc24                                                               @@commandline          
zlib-devel.x86_64                                                                     1.2.8-10.fc24                                                               @@commandline          
znc.x86_64                                                                            1.6.5-1.fc25                                                                @@commandline 

I am only interested in names of the packages, i.e. the value of the first column but only until the . (e.g. znc.x86_64 -> znc).

How could I merge results from this command output into a single line separated with spaces (e.g. zip zlib zlib-devel znc)?


awk + sort solution:

dnf list installed | awk -F. -v ORS="\0" '{print $1" "}' | sort -zu && echo ""

The output should look like:

zenity zip zlib zlib-devel znc

-v ORS="\0" - considering input as zero-terminated records

sort -zu - to get unique zero-terminated values

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.