Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to parse version number from a package list and print out package name and version in separate lines?

The package list looks like this:

ncurses-6.2  
netifd-2020-06-06-51e9fb81  
net-snmp-5.9.1  
nettle-3.5.1  
nginx-util-1.4  
odhcpd-full  
openldap-2.4.48  
openssl-1.1.1g    
pciutils-3.7.0  
pcre-8.44  
pcsc-lite-1.8.13  

I want to print out like this

name: ncurses-6.2  
version: 6.2  
name: netifd-2020-06-06-51e9fb81  
version: 2020-06-06-51e9fb81  
name: net-snmp-5.9.1  
version: 5.9.1  
.  
.  
.  

Currently, I use

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

awk '{ print "- name: "$1"\n version: "}' package_list

to print, but don’t know how to print the version number.

>Solution :

You may try this awk:

awk '{
   print "name:", $0
   sub(/^[^-]+(-[^0-9][^-]*)*(-|$)/, "")
   print "version:", $0
}' file

name: ncurses-6.2
version: 6.2
name: netifd-2020-06-06-51e9fb81
version: 2020-06-06-51e9fb81
name: net-snmp-5.9.1
version: 5.9.1
name: nettle-3.5.1
version: 3.5.1
name: nginx-util-1.4
version: 1.4
name: odhcpd-full
version:
name: openldap-2.4.48
version: 2.4.48
name: openssl-1.1.1g
version: 1.1.1g
name: pciutils-3.7.0
version: 3.7.0
name: pcre-8.44
version: 8.44
name: pcsc-lite-1.8.13
version: 1.8.13
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading