LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 10-23-2006, 10:14 AM   #1
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Rep: Reputation: 15
parsing fields of a file


Hi
I have a file containing the list of rpms as below:
I would like to extract the rpm ( excluding the version details)

My problem is if the list simply contained rpms like

4Suite-1.0-3
acl-2.2.23-5
alchemist-1.0.34-1
anacron-2.3-32
apmd-3.0.2-24
automake14-1.4p6-12
automake15-1.5-13
automake16-1.6.3-5
automake17-1.7.9-5
elfutils-libelf-0.97-5
emacs-common-21.3-19.EL
fonts-xorg-base-6.8.1-1
and so on... If it contained the entries only like

4Suite-1.0-3
acl-2.2.23-5
alchemist-1.0.34-1,
then it would not have been a problem as i can grep the first field using - as a delimiter. But here as it has other entries like

automake17-1.7.9-5
elfutils-libelf-0.97-5
emacs-common-21.3-19.EL
fonts-xorg-base-6.8.1-1

It is not possible to do so. ( In the case of automake17-1.7.9-5), I simply need the output as automake.

How do I do it ? Your help will be highly appreciated
Thank you
 
Old 10-23-2006, 10:33 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,451
Blog Entries: 54

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
"cat /some/file | while read i; do i="${i%%-[0-9]*}"; echo ${i%%[0-9][0-9]}; done" should do.
The RPM equivalent is "rpm -qa --queryformat="%{NAME}\n"", just in case. Way easier.


( In the case of automake17-1.7.9-5), I simply need the output as automake.
Be aware the package *may* be called "automake17" for a purpose...
 
Old 10-26-2006, 02:16 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,288

Rep: Reputation: 174Reputation: 174
what are you actually trying to do?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Parsing Fields LDAP wwnexc Linux - Software 4 09-15-2006 03:17 AM
cut fields in a file christina_rules Linux - Newbie 12 07-15-2006 10:00 AM
Manipulating Fields Of Flat File Prasun1 General 10 09-29-2005 11:42 AM
Need help with file parsing BrianK Programming 2 09-02-2005 05:58 PM
Displaying fields in wtmp file? eclapton1 Programming 1 06-26-2004 09:51 PM


All times are GMT -5. The time now is 11:17 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration