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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using grep for matching arrays 1

Status
Not open for further replies.

nrich239

Programmer
Jun 9, 2004
22
US
I need to compare 2 Error logs and display only the new errors.
Basically I need it to go through and anything that's in file A but not in file B needs to be shown.

I got this from someone else but they used it to match numbers and it doesn't work as well for text.
@out is initialized to the newer of the files.
@early is the older file.


## For each value $word in @early
foreach $word (@early) {
## Remove from @out elements whose value is $word
@out = grep (!/^$word$/, @out);
}
print "@out\n";
 
Thanks, I didn't know that existed.
That makes this so much easier
 
Is there anyway to have the results that comm displays saved to a file?
 
yup, pipe it into a file by tackng on a "> filenamehere" at the end of your command.

___________________________________
[morse]--... ...--[/morse], Eric.
 
i also did not know about comm. IMHO it is a bit awkward for this requirement as the 2 files must, presumably, be separately sorted, possibly into temp files.1 liner:

sort filea fileb fileb|uniq -u
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top