To delete the common parts (version and suffix) to get the package name

I have lots of package version +suffix full name, but I just want to get the package name, which means delete the common parts

eg:

dtc-1.3.0+gitAUTOINC+033089f29099bdfd5c2d6986cdb9fd07b16cfde0-r4.1.x86_64.rpm            dtc-dev-1.3.0+gitAUTOINC+033089f29099bdfd5c2d6986cdb9fd07b16cfde0-r4.1.x86_64.rpm        dtc-staticdev-1.3.0+gitAUTOINC+033089f29099bdfd5c2d6986cdb9fd07b16cfde0-r4.1.x86_64.rpm
dtc-dbg-1.3.0+gitAUTOINC+033089f29099bdfd5c2d6986cdb9fd07b16cfde0-r4.1.x86_64.rpm        dtc-misc-1.3.0+gitAUTOINC+033089f29099bdfd5c2d6986cdb9fd07b16cfde0-r4.1.x86_64.rpm  

out put

dtc
dtc-dev
dtc-static-dev
dtc-misc

another example is:

openvswitch-1.10.0-r4.atom_intel.rpm             openvswitch-dbg-1.10.0-r4.atom_intel.rpm         openvswitch-doc-1.10.0-r4.atom_intel.rpm         openvswitch-switch-1.10.0-r4.atom_intel.rpm openvswitch-controller-1.10.0-r4.atom_intel.rpm  openvswitch-dev-1.10.0-r4.atom_intel.rpm         openvswitch-pki-1.10.0-r4.atom_intel.rpm         openvswitch-testing-1.10.0-r4.atom_intel.rpm  
 

to get


openvswitch
openvswitch-dpg
openvswitch-doc
openvswitch-dev
openvswitch-pki
openvswitch-testing

awk -F'-[0-9].*' '{print $1}'
1 Like
awk '{for(i=1;i<=NF;i++) {match($i, "-[0-9]");print substr($i,1,RSTART-1)}}' myFile

Good idea, but there're multiple fields in a record/line. Adopting an idea:

awk -F'-[0-9]|[ ][ ]*' '{for(i=1;i<=NF;i+=2) print $i}' myFile

The solution posted by in2nix4life covers however many fields there maybe in a record or line...

Hmmmm... just tried one of the OPs samples - :

openvswitch-1.10.0-r4.atom_intel.rpm             openvswitch-dbg-1.10.0-r4.atom_intel.rpm         openvswitch-doc-1.10.0-r4.atom_intel.rpm         openvswitch-switch-1.10.0-r4.atom_intel.rpm openvswitch-controller-1.10.0-r4.atom_intel.rpm  openvswitch-dev-1.10.0-r4.atom_intel.rpm         openvswitch-pki-1.10.0-r4.atom_intel.rpm         openvswitch-testing-1.10.0-r4.atom_intel.rpm

and only getting openvswitch as it should.