LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
 
LinkBack Search this Thread
Old 02-25-2010, 09:03 PM   #1
jbeiter
Member
 
Registered: Jul 2004
Posts: 101

Rep: Reputation: 15
need help with sed/awk


at least I assume this would best be done with sed/awk. I have a list of 900+ rpms that need to be installed to match a dev system.. problem is 400 of them are already installed so rpm is bitching then giving up.

I need to take my list of 400 "sorry blah.blah.blah is already installed" and remove the blah.blah.blah line from my script of 900+ wgets.

so I need to parse file 1 and each line that matches a line with that package in file 2, removes it from the resulting file 3. (at least that's my line of thought)

I'm not much of a programmer and I'm sure someone out there can figure this out in minutes compared to the many days it will take me to get this to work.

Here is a sample of lines from each file:

file1:
package basesystem-8.0-5.1.1 is already installed

file2:
wget http://foo-server/RHEL5/basesystem-8.0-5.1.1.noarch.rpm

so file three will leave all of the wget for packages which do not appear in file1 (or some clever way of just removing those lines from file2.)

If there's an easier way to do this (ie: better way to run rpm -ivh *.rpm that won't choke) or using bash or perl, I'm open to enlightenment.
 
Old 02-25-2010, 09:20 PM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
Code:
for i in  $(awk '{print $2}' file1); do
 sed -i "/$i/d" file2
done
Looks pretty simple, and is not fully tested by me with your exact files (and their contents) so make sure to have a backup of your file2 before proceeding.

This just grabs each occurrence of the packagename in file1, and deletes any line containing that package, from file2.


Sasha
 
1 members found this post helpful.
Old 02-26-2010, 05:29 AM   #3
jbeiter
Member
 
Registered: Jul 2004
Posts: 101

Original Poster
Rep: Reputation: 15
I think this worked. Thank you so much Sasha!

ps: I love your quote
 
Old 02-26-2010, 05:50 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,193

Rep: Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784
Just a quick two cents, but you can replace the awk with a simple cat if you like:

for i in "$(cat file1)"; do
sed -i "/$i/d" file2
done

Side note: Grapefruitgirl - how do you get the code box?
 
Old 02-26-2010, 06:33 AM   #5
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 582

Rep: Reputation: 129Reputation: 129
Go to advanced in Quick Reply box and select the text you want in the code box and hit # in the menu.
 
Old 02-26-2010, 07:06 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by grail View Post
Just a quick two cents, but you can replace the awk with a simple cat if you like:

for i in "$(cat file1)"; do
sed -i "/$i/d" file2
done

Side note: Grapefruitgirl - how do you get the code box?
How is this equivalent to the AWK statement which only returns the 2nd field?
 
Old 02-26-2010, 08:18 AM   #7
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,193

Rep: Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784
Sorry, my bad ... thought it was only the filename there <walks off smaking himself about the head and ears >
 
Old 02-26-2010, 11:13 AM   #8
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
Quote:
Originally Posted by whizje View Post
Go to advanced in Quick Reply box and select the text you want in the code box and hit # in the menu.
@ grail,

yes, the above will get you [code] tags too, by going to the "Advanced Editor" and pressing the "#" icon; but usually, since most of the time I'm using the "Quick Reply" field at the bottom of a page, I just manually put the [code] tags above and below the code.

code <--here
blah blah
/code <--and here

And put those words "code" in [square brackets]

Sasha
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with awk or sed. tuxtutorials Linux - Software 3 07-23-2009 03:26 PM
Help with awk or sed. tuxtutorials Linux - Software 1 07-23-2009 02:45 AM
sed or awk ilo Programming 1 08-22-2008 10:38 AM
SED/AWK help bioinformatics_guy Linux - Newbie 1 08-12-2008 05:07 AM
Sed and Awk Gins Programming 7 04-19-2006 10:32 AM


All times are GMT -5. The time now is 05:57 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