Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract one of multiple files with similar syntax

Status
Not open for further replies.

kHz

MIS
Dec 6, 2004
1,359
US
I run an rpm -qa and get output of all packages installed on a Linux server. Then on another server I have a list of all RPM packages available. I need to compare the rpm list to the 'all' list and get just that one match even though there are similar names.

Example (rpm -qa list):
glibc-2.6.3-1.44.3

Example (all RPM packages available):
glibc | 2.6.3 | 1.44.3
glibc-html | 2.3.1 | 1.44.2

What I need to match is just the glibc on the first line of the example but I get all the glibc packages because they contain glibc when doing a grep. I tried using something with the shell by just getting the length of the filename (glibc which is 5) in the rpm -qa list and comparing that with each filename in the "all" list and if the file is a length of 5 and then matches the name then I use it. It still isn't giving me the correct output though.

Is there an easier way to only match glibc and not all other glibc* packages?

Thanks!!
 
There are many packages that match this scenario. Probably 6,000+ lines in the 'all' list, but only 250 or so in the rpm -qa generated list.

Thanks!!
 
Typed, untested:
awk -F'[ |]+' '{NR==FNR{a[$1];next}$1"-"$2"-"$3 in a' rpmlist alllist > matchlist

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top