compare two text files

Hi:
I offten have a need to compare a small file with a big file and make sure all the text in the small file are also in the big file. for example,
small file:
Group1
ABC=
DEF=
Group2
GHI=
JKL=
Big file:
Group1
ABC=AAAA,
DEF=BBBB,
CBA=CCCC,
FED=DDDD;
Group2
GHI=EEEE,
IHG=FFFF,
JKL=GGGG,
LKJ=HHHH;
Does anyone have any codes that can do this or can do similar comparision?
Thanks
Sam of Houston.


Comments

  • : Hi:
    : I offten have a need to compare a small file with a big file and make sure all the text in the small file are also in the big file. for example,
    : small file:
    : Group1
    : ABC=
    : DEF=
    : Group2
    : GHI=
    : JKL=
    : Big file:
    : Group1
    : ABC=AAAA,
    : DEF=BBBB,
    : CBA=CCCC,
    : FED=DDDD;
    : Group2
    : GHI=EEEE,
    : IHG=FFFF,
    : JKL=GGGG,
    : LKJ=HHHH;
    : Does anyone have any codes that can do this or can do similar comparision?
    : Thanks
    : Sam of Houston.
    :

    [blue]If you know that the stored data format is the same in both files, then you could simply read in both files at once, loop through the shorter file until EOF or until strcmp returns something other than 0.

    Possible problems: you may need to look into fseek, ftell, and so forth if you have to read the larger file in random areas. Depending on what you wish to read, you may also require strncmp instead of strcmp.

    loop(smaller file){

    read larger file line
    if(strcmp(line_file1, line_file2) == 0) proceed
    else break out of smaller loop
    }[/blue]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion