File comparison

I

IJALAB

Hi All,

Thanks for all the guidance.

I have two files, which are of similar output but logged at different
times. They need to be compared for any changes in the data logged. But
the comparison should start only when the whole line matches. For ex:

I am pasting only few bytes from the log.It is actually 48 bytes wide.

File 1's output:
F0 00 10 00
F0 00 00 00
F0 00 7F 15 - from this point output matches with file2
F0 00 00 01
F0 00 0F FF
F0 00 7F 00
F0 00 FB 5D
F0 00 00 00

file2's output:

F0 00 7F 15
F0 00 00 01
F0 00 0F FF
F0 00 7F 00
F0 00 FB 5D
F0 00 00 00

So, I started like :

open(OUT, ">FileOutput.txt") || die "Can't open output
file.";
open(IN1, "<File1.txt") || die "Can't open input file 1.";
open(IN2, "<File2.txt") || die "Can't open input file
2.";

while (<IN1>) && (<IN2>)
{
foreach $line1(<IN1>)
{
foreach $line2(<IN2>)
{
if ($line1 = $line2)
{
print "Lines match";
}
else
{ print "Lines are not matching";}
}
}
}

but I dont know any better idea to compare the file outputs. Also, any
of these files might have some extra lines.

Any better idea that I can implement in Perl.

Bala
 
A

anno4000

IJALAB said:
Hi All,

Thanks for all the guidance.

I have two files, which are of similar output but logged at different
times. They need to be compared for any changes in the data logged. But
the comparison should start only when the whole line matches. For ex:

I am pasting only few bytes from the log.It is actually 48 bytes wide.

File 1's output:
F0 00 10 00
F0 00 00 00
F0 00 7F 15 - from this point output matches with file2
F0 00 00 01
F0 00 0F FF
F0 00 7F 00
F0 00 FB 5D
F0 00 00 00

file2's output:

F0 00 7F 15
F0 00 00 01
F0 00 0F FF
F0 00 7F 00
F0 00 FB 5D
F0 00 00 00

So, I started like :

open(OUT, ">FileOutput.txt") || die "Can't open output
file.";
open(IN1, "<File1.txt") || die "Can't open input file 1.";
open(IN2, "<File2.txt") || die "Can't open input file
2.";

while (<IN1>) && (<IN2>)
{
foreach $line1(<IN1>)
{
foreach $line2(<IN2>)
{
if ($line1 = $line2)
{
print "Lines match";
}
else
{ print "Lines are not matching";}
}
}
}

but I dont know any better idea to compare the file outputs. Also, any
of these files might have some extra lines.

Any better idea that I can implement in Perl.

That looks like something better done by diff, perhaps with some
Perl post-processing. Look into "diff -y" and related options,
if you're in a Unix or (I suppose) Cygwin environment. Otherwise
I don't know, but I'd still look for a specialized external program.
The algorithm you're looking for is far from trivial and not easy
to make fast.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top