Diff files with regex comparing

M

Michael Yang

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!!
 
J

Josef Moellers

Michael said:
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.
 
J

Josef Moellers

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.
 

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,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top