Line compare 2 files



Help for C/C++ for MVS, OS/390 C/C++, z/OS C/C++ and C/C++ Productivity Tools for OS/390

Line compare 2 files

Postby Greenhouse » Thu Aug 19, 2010 12:21 pm

Hi,

Which way is most efficient to compare two files for line equality?
Greenhouse
 
Posts: 25
Joined: Tue Sep 02, 2008 1:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Line compare 2 files

Postby enrico-sorichetti » Thu Aug 19, 2010 5:07 pm

from a practical or an algorithmic point of view

ever heard of ISPF superc, or HLASM toolkit superc ???
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Line compare 2 files

Postby NicC » Thu Aug 19, 2010 5:07 pm

SUPERC, COMPAREX, other utilities for file compare. Possibly even SORT.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Line compare 2 files

Postby Greenhouse » Sun Aug 22, 2010 12:58 pm

I meant using language constructs without external tools.
Greenhouse
 
Posts: 25
Joined: Tue Sep 02, 2008 1:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Line compare 2 files

Postby enrico-sorichetti » Sun Aug 22, 2010 4:37 pm

the question as posed does not make any sense
kind way of telling that the question is ...

what do You want to compare...
are the files sorted or not
what kind of changes do You want to identify
do You want to compare at line level or also at block level
... and so on and so on

googling for ( for example ) file compare algorithms or two files match
You will find lots of links which will help You to ask the question in a better way

and at last how does this relate to C/C++ languages only ???
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Line compare 2 files

Postby dick scherrer » Sun Aug 22, 2010 10:49 pm

Hello,

I meant using language constructs without external tools.
Nearly anything can be written but most organizations are not willing to pay to have code written that already exists. . .

Is this for your learning?

You need to post a bit of sample data from 2 files and the results you want when your code executes using the sample input data.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Line compare 2 files

Postby Greenhouse » Mon Aug 23, 2010 11:04 am

The whole story is that i wrote some REXX and then just for my learning I try to rewrite it in C++.

In REXX I have line level comparison of two (sorted) files and report all difference with related line number.

What I wanted to do in C++ is to at least preform line level comparison and at first difference to report it and compare next pair.

As I thought load module will be faster then interpreted program, but it wasn't.

string f_res = "OK ";                                   
                                                         
ifstream fprep;                                         
fprep.open(prep_fname.c_str(), ios_base::in);           
                                                         
if(!fprep.is_open())                                     
   throw E(prep_fname += " file cannot be open", 8);     
                                                         
ifstream fexec;                                         
fexec.open(exec_fname.c_str(), ios_base::in);           
                                                         
if(!fexec.is_open())                                     
   throw E(exec_fname += " file cannot be open", 8);     
                                                         
string pline;                                           
string eline;                                           
                                                         
while(!fprep.eof())                                     
{                                                       
   if(fexec.eof())                                       
   {                                                     
      f_res = "NOK";                                     
      cout << "WORK CMPR " << tstid                     
         << " Different work files sizes.\n";           
      break;                                             
   }                                                     
                                                         
   getline(fprep, pline);                               
   getline(fexec, eline);                               
                                                         
   if(pline != eline)                                   
   {                                                     
      f_res = "NOK";                                     
      cout << "WORK CMPR " << tstid                     
         << " Difference between lines of work files.\n";
      break;                                             
   }                                                     
}
fprep.close();
fexec.close();
             
return f_res;
Greenhouse
 
Posts: 25
Joined: Tue Sep 02, 2008 1:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Line compare 2 files

Postby dick scherrer » Mon Aug 23, 2010 7:04 pm

Hello,

Suggest you look at the amount of cpu resource used. The rexx probably takes more cpu time.

The reason both run in similar amounts of elapsed time is probably because both are limited by the speed of the dasd. . . You may need to run a higher volume of test data to see much of a difference.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to C, C++

 


  • Related topics
    Replies
    Views
    Last post