Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Diff files with regex comparing (http://www.velocityreviews.com/forums/t903074-diff-files-with-regex-comparing.html)

Michael Yang 05-13-2007 03:40 PM

Diff files with regex comparing
 
Here I have two files to diff, I want them compared with my rules.
Let's one is base file, the other is result file:
base file:
Connected to the '.*'
Hello everyone, I am .*
Glad to see you, .*

result file:
Connected to the 'www.perl.com'
Hello everyone, I am michael
Nice to see you, all

There are regex string ".*" in the base file, indicating that it could
be replaced by any string. When the two lines being compared, I want
it be considered equal when the ".*" matches the couter-part of the
other, like the first two lines in the files shown above.

So when diff these two files, only the last line is the difference
data after diff.
Glad to see you, .*
Nice to see you, all

I need to change the rules of diff program, and for that I need to
implement my own diff algorithm.
Is there any ways simpler to achieve this?

I don't know if there are any interface providing user-defined
comparison function to diff.
If there is, I can implement my own comparison function telling it how
to compare two lines and pass the function as the reference to the
diff function. The diff function will compare and diff files using my
comparison rules.

Your helps are greatly appreciated!!


Josef Moellers 05-14-2007 08:49 AM

Re: Diff files with regex comparing
 
Michael Yang wrote:
> Here I have two files to diff, I want them compared with my rules.
> Let's one is base file, the other is result file:
> base file:
> Connected to the '.*'
> Hello everyone, I am .*
> Glad to see you, .*
>
> result file:
> Connected to the 'www.perl.com'
> Hello everyone, I am michael
> Nice to see you, all
>
> There are regex string ".*" in the base file, indicating that it could
> be replaced by any string. When the two lines being compared, I want
> it be considered equal when the ".*" matches the couter-part of the
> other, like the first two lines in the files shown above.
>
> So when diff these two files, only the last line is the difference
> data after diff.
> Glad to see you, .*
> Nice to see you, all
>
> I need to change the rules of diff program, and for that I need to
> implement my own diff algorithm.
> Is there any ways simpler to achieve this?
>
> I don't know if there are any interface providing user-defined
> comparison function to diff.
> If there is, I can implement my own comparison function telling it how
> to compare two lines and pass the function as the reference to the
> diff function. The diff function will compare and diff files using my
> comparison rules.
>
> Your helps are greatly appreciated!!


1. Be patient, posting the same request twice within a few minutes with
different subject lines is bad.
2. This is no place to ask for ready-to-run scripts. Have a try
yourself, post your code and we'll help getting bugs ironed out.

--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html


Josef Moellers 05-14-2007 08:51 AM

Re: Diff files with regex comparing
 
Michael Yang wrote:
[ Problem description deleted ]

> Your helps are greatly appreciated!!


1. Be patient, posting the same request twice within a few minutes with
different subject lines is bad.
2. This is no place to ask for ready-to-run scripts. Have a try
yourself, post your code and we'll help getting bugs ironed out.

--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html



All times are GMT. The time now is 11:31 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57