LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   parsing fields of a file (http://www.linuxquestions.org/questions/programming-9/parsing-fields-of-a-file-494855/)

sang_froid 10-23-2006 11:14 AM

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

unSpawn 10-23-2006 11:33 AM

"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...

bigearsbilly 10-26-2006 03:16 AM

what are you actually trying to do?


All times are GMT -5. The time now is 03:05 AM.