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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To delete the common parts (version and suffix) to get the package name
# 1  
Old 11-14-2013
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:

Code:
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

Code:
dtc
dtc-dev
dtc-static-dev
dtc-misc

another example is:

Code:
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
Code:

openvswitch
openvswitch-dpg
openvswitch-doc
openvswitch-dev
openvswitch-pki
openvswitch-testing
# 2  
Old 11-14-2013
Code:
awk -F'-[0-9].*' '{print $1}'

This User Gave Thanks to in2nix4life For This Post:
# 3  
Old 11-14-2013
Code:
awk '{for(i=1;i<=NF;i++) {match($i, "-[0-9]");print substr($i,1,RSTART-1)}}' myFile

# 4  
Old 11-14-2013
Quote:
Originally Posted by in2nix4life
Code:
awk -F'-[0-9].*' '{print $1}'

Good idea, but there're multiple fields in a record/line. Adopting an idea:
Code:
awk -F'-[0-9]|[ ][ ]*' '{for(i=1;i<=NF;i+=2) print $i}' myFile

# 5  
Old 11-14-2013
Quote:
Originally Posted by vgersh99
Good idea, but there're multiple fields in a record/line. Adopting an idea:
Code:
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...
# 6  
Old 11-14-2013
Quote:
Originally Posted by shamrock
The solution posted by in2nix4life covers however many fields there maybe in a record or line...
Hmmmm... just tried one of the OPs samples - :
Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to install older package version on Ubuntu 18.04?

Hello, I'm running Ubuntu 18.04 and I would like to install libboost-python version 1.46. Currently I have installed version 1.65: wakatana@local-machine:~$ dpkg -l | grep libboost-python ii libboost-python-dev 1.65.1.0ubuntu1 amd64 ... (1 Reply)
Discussion started by: wakatana
1 Replies

2. Solaris

Check that supersede of package version is installed

I need a programmatic way to check, that supersede of required package is installed. At Linux I do it using rpmvercm utility to compare installed package version to my minimal requirement. So - I need analog of Linux "rpmvercm" utility for Solaris (10/11) Let us say - I know that minimal version... (10 Replies)
Discussion started by: zuismanm
10 Replies

3. Shell Programming and Scripting

Delete specific parts in a .txt file

Hi all, I desperately need a small script which deletes everything in a particular .txt file when "Abs = {" appears till "},", and also when "B-1 = {" appears till "}," I would like all the text in between of those instances to be deleted, however, other text to be unedited (kept as it is).... (12 Replies)
Discussion started by: c_lady
12 Replies

4. Shell Programming and Scripting

Remove version numbers from package lists

I just upgraded my laptop from Fedora 13 to 14, and normally, before I do the upgrade (Fresh install) I run an rpm command to make a list of all the packages I have installed, but without the version and architectures specified, so that I can just feed that list to yum after the upgrade to... (2 Replies)
Discussion started by: Tsuroerusu
2 Replies

5. Shell Programming and Scripting

Package version testing script

I was wondering if anyone already had a script to check rpm packages versions x.x.x or greater. so I could do a: # CheckRpmVersion Somepackage-1.2.3 And would output: whether the package is installed or not and if it was equal to or greater than the version 1.2.3. I know I can pull out... (0 Replies)
Discussion started by: Ikon
0 Replies

6. Debian

Package updated to same version

Hi, I recently did slight modifications to the basename utility from the coreutils package. I downloaded the source by typing "apt-get source coreutils", added a new option to the program, updated the respective manpage, build and installed it using "dpkg-buildpackage -uc -b && dpkg -i... (0 Replies)
Discussion started by: Gunther
0 Replies

7. Shell Programming and Scripting

Delete parts of a string of character in one given column of a tab delimited file

I would like to remove characters from column 7 so that from an input file looking like this: >HWI-EAS422_12:4:1:69:89 GGTTTAAATATTGCACAAAAGGTATAGAGCGT U0 1 0 0 ref_chr8.fa 6527777 F DD I get something like that in an output file: ... (13 Replies)
Discussion started by: matlavmac
13 Replies

8. UNIX for Dummies Questions & Answers

package version

hi, I have this problem. I run a script to check which version of a given package is installed and I need something returning a meaningfull answer also if the installation was done with the sources. Let's say that, a priori, I do not know how the package was installed. So far I have... (0 Replies)
Discussion started by: gcastell
0 Replies

9. UNIX for Dummies Questions & Answers

How to rename multiple files with a common suffix

Hi, There are multiple files like file1_11 file2_11 file3_11.....and so on. How to rename them such tht the suffix _11 is removed and they become file1, file2, file3. Any help is appreciated. Regards er_ashu (1 Reply)
Discussion started by: er_ashu
1 Replies

10. UNIX for Dummies Questions & Answers

Most common version of UNIX on production systems

I am new to UNIX (about a year) and learning as fast as I can. I am an instructor teaching UNIX and have two labs with Ultra 10 333 MHz, Sun Blade 1000 1 GHz, Blade 100, and Two Enterprise 250 Servers. We are currently teaching our classes using the Solaris 2.10 OS, downloaded in May 2006, I am not... (7 Replies)
Discussion started by: dutchman
7 Replies
Login or Register to Ask a Question