compare strings to report error

Hi,

I am a newbie in unix.

I have to solve a problem.

I have a file ( properties.file) with different (key=value) values, as below

agent.x=xyz
agent.y=xyz
agent.z=xyz

I have some other files in the system in different locations with different (key=value) values.

example file is properties1.txt
agent.x=123
method=xyz()

example file is properties2.txt
agent.y=xyz
method=adc()

Now I am in need of a program which reads the first file properties.file,
read all the keys, i.e agent.x,agent.y and then compare them with the files properties1.txt and properties2.txt.

If it finds any key which is not in any of the properties1.txt and properties2.txt it has to report an error.
as an example agent.z in properties.file is not present in any of properties1.txt and properties2.txt

it has to report error only once, saying key is not present.

I am in need of this solution, please help me in this.

Thanks in advance,
RaghuDeep Amilineni

Hi

This one could do that..

#!/bin/sh
for f in `cat properities.txt`
do
        grep -w "$f" properities1.txt
        if [ $? -eq 0 ];then
        sed '/'$f'/d' properities1.txt > out.lst
        mv out.lst properities.1txt
        break;else
                grep -w $f properities2.txt
                if [ $? -eq 0 ];then
                sed '/'$f'/d' properities2.txt > out.lst
                mv out.lst properities2.txt
                break;else
                echo "$f - Not present in any of the properities file"
                sed '/'$f'/d' properities2.txt > out.lst
                mv out.lst properities2.txt
                break;fi;fi;
done
 

Thanks
Sha

thank you very much for the code..is there any way to do with out moving data into files?

Hi,

if you try now...this will not remove any data from the files..

#!/bin/sh
for f in `cat properities.txt`
do
grep -w "$f" properities1.txt
if [ $? -eq 0 ];then
break;else
grep -w $f properities2.txt
if [ $? -eq 0 ];then
break;else
echo "$f - Not present in any of the properities file"
break;fi;fi;
done

Thanks
Sha

Thank you very much !

#!/usr/bin/perl
my ($f1, $f2, $f3) = ("properties.file", "properties1.txt", "properties2.txt");
sub load {
        open(F, "< $_[0]") or die "Could not open file $_[0]: $!\n";
        $_[1]->{(split(/=/, $_))[0]} = (split(/=/, $_))[1] foreach(<F>);
}
load($f1, \%f1); load($f2, \%f2); load($f3, \%f3);
foreach(keys %f1) {
        print "$_ Not found in $f2 and $f3\n" unless( (exists($f2{$_})) || (exists($f3{$_})) );
}