in reply to Comparing 2 files!!

It's not (just) because the words or phrases don't start at the beginning of a line. If you use hashes like that, the two lines would have to match EXACTLY, byte for byte, without the slightest difference.

Also, your current program will give you a false positive if a line is duplicated in either of the two files.

You need to specify more precisely just what you mean by "match." Do you mean that a line of one file is a substring of a line in the other file? If f1.txt has a line with just the four letters "bell", should that match a line in f2.txt that has the phrase "the antebellum south"?

Once you specify what you want, we can be more help.

Replies are listed 'Best First'.
Re: Re: Comparing 2 files!!
by nofernandes (Beadle) on Jul 14, 2003 at 16:12 UTC

    The main purpose is to compare two files and match the contents of one file in order to get the line number of that match!

    One of the files has code comments! And the other has the source code from where the comments where extracted!

    Example:
    File1.txt
    public class Finger { //Commment 1 public static void main(String[] arguments) {//com 2 String user; String host; //comm3

    File2.txt
    //Comment 1 //com 2 //comm3
    Result
    Line 1: //Comment 1 Line 2: //Com 2 Line 5: //comm3

    Thank you all for your help!!
      If you have grep on your system, this would work:
      grep -F -n -f File2.txt File1.txt