Question:

How can I compare 2 text files using a batch file? ?

by  |  earlier

0 LIKES UnLike

I have two text files. One with the name

list1.txt that contains the master list that we are comparing it to.

List1.txt

grape

apple

strawberry

list2.txt has

orange

apple

grape

What I need is to compare if the information in those two files have the same information and show the result if they are in another text file. The result text file should have either a true or false answer. For example in this case if should show

grape TRUE because its located in both files

apple TRUE

orange FALSE because its located on only one file

strawberry FALSE

Please help

 Tags:

   Report

4 ANSWERS


  1. A batch file itself won't do it but if you must use a batch file, use it to run a text comparison program that will do it.


  2. I'd use sort and fc (file compare).

    I don't know why you'd need that format, unless this is your homework.

  3. Check out "comp"

    C:\>comp /?

    Compares the contents of two files or sets of files.

    COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[LINE]]

      data1      Specifies location and name(s) of first file(s) to compare.

      data2      Specifies location and name(s) of second files to compare.

      /D         Displays differences in decimal format.

      /A         Displays differences in ASCII characters.

      /L         Displays line numbers for differences.

      /N=number  Compares only the first specified number of lines in each file.

      /C         Disregards case of ASCII letters when comparing files.

      /OFF[LINE] Do not skip files with offline attribute set.

    To compare sets of files, use wildcards in data1 and data2 parameters.

  4. MS-DOS and Windows does NOT have this capability built-in.

    What you want can be done with a GREP variant by combining the two files into a single file but adding a ,1 or ,2 respectively per line (easy enough with GREP), then comparing that single file by itself. However, I'll defer the actual syntax to a GREP master.  

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions