LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2008, 01:58 PM   #1
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Rep: Reputation: 30
Splitting out specific portions of a rpm package using awk but preserving some?


Hi, I am looking for a method of getting rid of the hole slew of numbers beind a rpm package name. Hoever I am stuck using awk.
Here is what I am trying to accomplish.

[root@linux RPMS]# ls -R vim* | sort
vim-common-6.3.046-0.40E.7.i386.rpm
vim-enhanced-6.3.046-0.40E.7.i386.rpm
vim-minimal-6.3.046-0.40E.7.i386.rpm
vim-X11-6.3.046-0.40E.7.i386.rpm


Problem: the version number behind every package.

Goal to strip out the 6.2828.i386.rpm from each package.

Attempt 1:

[root@linux RPMS]# ls -R vim* | awk -F- '{ print $1 $2 }'
vimcommon
vimenhanced
vimminimal
vimX11



Problem: How do I preserve the "-" character between the vim packages if I am using it as a delimiter?

Thanks
 
Old 05-16-2008, 02:51 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Package names may have a different number of fields separated by hyphen in their name, so it is not a simple task to extract the name using awk. But you can use the rpm command itself, using the --queryformat option. This let you ask rpm to print only the names of the packages, without version number and architecture. For example if you have some downloaded packages you can try
Code:
rpm -qp --queryformat '%{NAME}\n' *.rpm
the format is in C-style, with specific tags like NAME, VERSION, RELEASE, ARCH and so on. To see the whole (long) list of available tags, use
Code:
rpm --querytags
 
Old 05-16-2008, 02:55 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by keysorsoze View Post
Problem: How do I preserve the "-" character between the vim packages if I am using it as a delimiter?
There is no relationship between the character you used as delimiter of the input (FS = Field Separator) and what you use as delimiter for the output (OFS = Output Field Separator). In any case, you can use the printf statement to customize the output at your desire:
Code:
awk -F- '{printf "%s-%s\n",$1,$2}'
 
Old 05-16-2008, 03:43 PM   #4
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Original Poster
Rep: Reputation: 30
Thanks, colucix your solution solved the issue, now if only I could have figured this out on my own!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete specific Range of lines Using sed , awk, grep etc. joyds219 Linux - Newbie 4 03-28-2008 08:59 AM
Replacing text on specific lines with sed or awk? Lantzvillian Linux - Newbie 5 10-17-2007 09:00 AM
How do I cut out a specific piece of a html page (using sed/awk or similar)? bomix Linux - General 2 10-08-2005 04:30 PM
Splitting audio files at specific time intervals quickfix Linux - Software 2 08-26-2005 07:18 AM
search for specific text in fields using awk Helene Programming 2 04-23-2004 12:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration