Compare two text file

i am comparing two text file by checking occurance of a line in file 1 by comparing it with each line in file 2(not line by line)
i have to print in 3rd text file as difference
please see my progrm and tell me modification required
package comp.vnet.comparator;
import java.io.*;
import comp.vnet.comparator.NewFile;
class FileComparator {
     public static void main(String[] args) throws IOException{
          String file1,file2,String1,String2;
          BufferedReader br1,br2;
          int fileCount1=0;
          int fileCount2=0;
          br1= new BufferedReader(new InputStreamReader (System.in));
          // File file = new File ("output.txt");
          FileWriter fstream = new FileWriter("out.txt");
          // FileOutputStream fo = new FileOutputStream("E:/Filecomparator/FileComparator/output.txt");
          System.out.println("Enter First file name");
          file1="b.txt";
          //file1=br1.readLine();
          System.out.println("Enter Second file name");
          file2="a.txt";
          //file2=br2.readLine();
          NewFile nf= new NewFile();
          br1=nf.creatingFile(file1);
          br2=nf.creatingFile(file2);
while ((String1= br1.readLine()) != null) {
     fileCount1++;
while ((String2= br2.readLine()) != null) {
     fileCount2++;
System.out.println("fileCount1+ : " + fileCount1);
System.out.println("fileCount2+ : " + fileCount1);
br1=nf.creatingFile(file1);
BufferedWriter out = new BufferedWriter(fstream);
for(int i=0;i<=fileCount1;i++)
     br2=nf.creatingFile(file2);
     String1=br1.readLine();
     for(int j=0;j<fileCount2;j++)
               String2=br2.readLine();
                    if ( String1.equals (String2) ) {
                         System.out.println("the line is equal");
                    else{
                    out.write(String1);
                         System.out.println(String1);
out.close();
br1.close();
br2.close();
          }

thanks alot for that reply
but there is some error
pleasse send me a nice reply

Similar Messages

  • Comparing two text files in a UNIX using shell programming

    Hi All,
    Sorry for posting a UNIX shell query on Database forums.
    I want to compare two text files using shell programming. The two text files are actually Business Objects output extracted in a text format. The two output files are not in a tabular format and are no way similar in looking. I want to take one file e.g. file1 as an input file and compare each line of file1 with the other file e.g. file2. During comparison I want to extract the differences found in another file and if possible the similar data as well.
    Below is how the files will look like
    File 1:
    BILL1000000 1111251 122222
    RMG1A2 023425100000000010001 11135 102650111100
    UHL1 *6999999* *454540001* Weekly *000*
    0544424556895PS DATA 01MPS100000/03 MR A A PERTH UTL1234567893106923455053106900000010000005
    File 2:
    AUTO
    APPLICATION=STARTPOINT
    START
    PROCESSING DATE=01012011
    1598301270320099TEST C E 00000031615 123456
    7854301276140499TES P 00000062943 234567
    UHL1 *6999999* *454540001* Weekly *000*
    5569931233333499/123456789 00000013396 345678
    4471931233333499ER K J 00000031835123456789012456789
    33652931233333499E J L 00000034729123456789012567890
    45783123333349921/123456789 00000039080 678901
    1452931233333499T R 00000040678123456789012789012
    59689312333334994/987654321 00000048614 890123
    4112931233333499/987654321 00000060631 901234
    1236931217836899 K S 00000043704 012345
    END
    As you can see above the file are not at all matching except for one record UHL1, but its just an example. As an output I would like to have a third file containing all these records, highlighting the differences, and a fourth file where in only the matched records should get populated.
    Please post any useful scripts related to the above scenario.
    Many Thanks.
    Edited by: 848265 on 06-Apr-2011 04:13

    Hi;
    For your issue i suggest close your thread here as changing thread status to answere and move it to Forum Home » Linux which you can get more quick response
    Regard
    Helios

  • Compare two text files in Powershell and if a name is found in both files output content from file 2 to a 3rd text file

    Is it possible using PowerShell to compare the contents of two text files line by line and if a line is found output that line to a third text file?
    Lets say hypothetically someone asks us to search a text file named names1.txt and when a name is found in names1.txt we then pair that with the same name in the second text file called names2.txt
    lets say the names shown below are in names1.txt
    Bob
    Mike
    George
    Lets say the names and contents shown below are in names2.txt
    Lisa
    Jordan
    Mike 1112222
    Bob 8675309
    Don
    Joe
    Lets say we want names3.txt to contain the data shown below
    Mike 1112222
    Bob 8675309
    In vbscript I used search and replace commands to get part of the way there like this
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("testing.txt", ForReading)
    strText = objFile.ReadAll
    objFile.Close
    strNewText = Replace(strText, "Mike ", "Mike 1112222")
    Set objFile = objFSO.OpenTextFile("testing.txt", ForWriting)
    objFile.WriteLine strNewText
    objFile.Close
    That script works great when you know the name you are looking for and the correct values. Lets say someone gives you a list of 1000 employees and says import these names into a list in the correct format and one sheet has the correct names only and
    the other sheet has lots of extra names say 200000 and you only need the 1000 you are looking for in the format from names2.txt.

    Sure,
    Here's a simple one:
    $names1 = "C:\names1.txt"
    $names2 = "C:\names2.txt"
    $names3 = "C:\names3.txt"
    Get-Content $names1 | ForEach-Object {
    $names1_Line = $_
    Get-Content $names2 | Where-Object {$_.Contains($names1_Line)} | Out-File -FilePath $names3 -Append
    This basically just reads $names1 file, line by line, and then read $names2 file line by line as well.
    If the line being evaluated from $names2 file contains the line being evaluated from $names1 file, then the line from $names2 file gets output to $names3 file, appending to what's already there.
    This might need a few more tinkering to get it to perform faster etc depending on your requirements. For example:
    - If either $names1 or $names2 contain a lot of entries (in the region of hundreds) then it will be faster to load the whole content of $names2 into memory rather than opening the file, reading line by line, closing and then doing the same for every single
    line in $names1 (which is how it is currently works)
    - Make sure that your comparison is behaving as expected. The .Contains method always does a case sensitive comparison, this might not be what you are after.
    - You might want to put a condition to ignore blank lines or lines with spaces, else they'll also be brought over to $names3
    Hopefully this will get you started though and ask if you have further questions.
    Fausto

  • Compare two text files

    Guys I have two .txt files like the one below
    00001                
    00002
    00003
    00004
    00005
    00006
    Some elements are missing from one to the other one...
    I need to compare these two and find the different elements of each file...
    I been reading the old post but I cant figure anything out of them
    Any ideas???

    Hi Darin,
    I am doing more or less same sort of thing but its between the two folder number of files to be compared and then copying the missing files lets say from folder A to folder B. The first part is not a problem to read the content and then compare them but what I am stuck in is that, I want to see while the VI is running that how much data is being copying and how much is remaining my be in percentage on some status bar or may be time or may be out of 55 files 20 files copyied 35 remaining etc. Can you please guide me through this how to do it any idea. It will be great help.
    Regards,
    Naqqash
    Naqqash

  • Compare two text files for matching data

    HI
    I want to compare data in two separate spreadsheet files and store the matching data in another spreadsheet file.
    like
    1)reading data from two spread sheets
    2)compare the data of fist one with second
    3)writing the matched data to third one.
    I am find difficulty in combining them to sort string bu string
    pls help me in this
    thanks
    jyohti

    hi
    i am implementing the following logic
    1)  textfile1--------->string to array
    2)textfile 2--------->string to array
    3) compare the elements (substring) of one array to other using for loop
    4)append the match to an array every time you find a match betwwen two arrays
    5)wriitng the result in new file
    i am strugulling in with 3) i have finshed 1,2,4and 5 th part
    problelms are with indexing and loop conditions for me...
    anyways i am trying and feeling like i will finish and post that soon....

  • Compare two .txt files and show result

    HI
    Could anybody show me how to compare two text files and show the result.
    i.e.
    textfile1.txt
    harry.denmark
    karry.sweden
    textfile2.txt
    harry.denmark
    karry.sweden
    marry.usa
    Compare
    result=
    marry.usa
    The text files I want to compare are how ever much larger than this example. (up to 2-3.000 words)
    anybody ??
    Sincerly
    Peder

    HI & thanks for reply
    I know almost nothing about java so could you or anybody please show me the code to do this? Or is it perhaps too large or difficult a code?
    I know how to compile a .java file and run it in prompt :-) and thats about it (almost)
    I offcourse understand if its too much to ask for :-)

  • Compare 2 text files

    Hello guys ... I want to compare two text files and then print line if the files are identical or not. What I have here is comparing linie by line and is printing after each line. How can compare all the text and after that just print if all the file is the same or not
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class compare
         public compare() throws Exception
              BufferedReader fx = new BufferedReader(new FileReader("1.txt"),1024);
              BufferedReader sx = new BufferedReader(new FileReader("2.txt"),1024);
    String s;
    String y;
    while ((s=fx.readLine())!=null)
    if ((y=sx.readLine()).equals (s))
         System.out.println("These line is the Same");
    else
             System.out.println("These line is different");
    sx.close();
    fx.close();
         public static void main(String[] args) throws Exception
                 new compare();
    }Thanks

    adi77 wrote:
    do you have any idee what could be the problem?Yes, all sorts of things.
    Don't compare Strings with ==
    sx.readLine() == fx.readLine()Use equals() instead
    sx.readLine().equals(fx.readLine())Do you know what the word 'different' means?
    if (sx.readLine() == fx.readLine())
            different = true;If so, then why do you set 'different' to true when the lines are the same?
    if (sx.readLine() != fx.readLine())
         System.out.println("This file is identical");You've already read all the lines in the files, why are you reading again? Use the boolean you set in your loop!
    if (different)
        System.out.println("File is different");

  • How to compare content of two text file using StreamTokenizer

    hi....
    i have two text files...containg field like(name,number,scheme) and(number,date,value)... i want to create a third file containg field like (name,number,date,scheme,value) by using these two table. how to create

    I think this code can solve your problem.
    private static final String DELIM = ",";
    * Compile two files.
    * @param file1 String the input file 1
    * @param file2 String the input file 2
    * @param file3 String the output file
    * @throws IOException error in reading/writing
    public void compileFiles(String file1, String file2, String file3) throws
            IOException {
            BufferedReader reader1 = new BufferedReader(new InputStreamReader(
                new FileInputStream(file1)));
            BufferedReader reader2 = new BufferedReader(new InputStreamReader(
                new FileInputStream(file2)));
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
                new FileOutputStream(file3)));
            String line1 = reader1.readLine();
            String line2 = reader2.readLine();
            while (line1 != null && line2 != null) {
                writer.write(compileLines(line1, line2));
                writer.newLine();
                line1 = reader1.readLine();
                line2 = reader2.readLine();
            reader1.close();
            reader2.close();
            writer.close();
        private String compileLines(String line1, String line2) {
            StringTokenizer tok1 = new StringTokenizer(line1, DELIM);
            StringTokenizer tok2 = new StringTokenizer(line2, DELIM);
            String name = tok1.nextToken();
            String number = tok1.nextToken();
            String scheme = tok1.nextToken();
            // ignore number
            tok2.nextToken();
            String date = tok2.nextToken();
            String value = tok2.nextToken();
            StringBuffer buffer = new StringBuffer();
            buffer.append(name);
            buffer.append(DELIM);
            buffer.append(number);
            buffer.append(DELIM);
            buffer.append(date);
            buffer.append(DELIM);
            buffer.append(scheme);
            buffer.append(DELIM);
            buffer.append(value);
            return buffer.toString();
        }

  • How to compare two XSD files programmatically

    Hi
    I want to compare two XSD files programmatically to find out whether one XSD is a sub set of another XSD(Means checking all the elements and attributes of one schema to be present in another schema).
    Please let me know how this can be done in an efficient way.
    Thanks in advance.
    Mithun K

    Or simply apply an oracle text index on your pdf column:
    SQL>  create table t (id integer primary key, bl blob)
    Table created.
    SQL>  declare
    bf bfile := bfilename('TEMP','b32001.pdf');
    bl blob;
    begin
    dbms_lob.createtemporary(bl,true);
    dbms_lob.open(bf,dbms_lob.lob_readonly);
    DBMS_LOB.LOADFROMFILE(bl, bf,dbms_lob.getlength(bf));
    insert into t values (1,bl);
    commit;
    dbms_lob.close(bf);
    dbms_lob.freetemporary(bl);
    end;
    PL/SQL procedure successfully completed.
    SQL>  create index t_idx on t (bl) indextype is ctxsys.context parameters ('filter ctxsys.auto_filter')
    Index created.
    SQL>  declare
       mklob   clob;
    begin
       ctx_doc.filter ('t_idx', '1', mklob, true);
       dbms_output.put_line (substr (mklob, 1, 250));
       dbms_lob.freetemporary (mklob);
    end;
    Oracle® Database
    Release Notes
    11
    g
    Release 1 (11.1) for Linux
    B32001-04
    November 2007
    This document contains important information that was not included in the
    platform-specific or product-specific documentation
    PL/SQL procedure successfully completed.This generates a text only version of your pdf and standard text comparison methods can be applied ....

  • How to compare two fmx files

    Hi,
    Is it possible to compare two fmx files , there are few differences between two fmx files , i wanted to know what are the differences.............Thanks.Bcj

    by converting fmb files into xml or text and then using gvimdiff (or similar) on unix or windows will show you the differences. For fmx files, as pointed earlier - you can only see that if they are different or not. On unix you can use strings command (for fmx files) and pipe it to a text file and then do a diff on the files, but that will not be too helpful either.

  • How to compare two PDF files through PLSQL

    Hi,
    Can any body help that how to compare two PDF files through PLSQL programing and gives the differences as output.
    Thanks,

    Or simply apply an oracle text index on your pdf column:
    SQL>  create table t (id integer primary key, bl blob)
    Table created.
    SQL>  declare
    bf bfile := bfilename('TEMP','b32001.pdf');
    bl blob;
    begin
    dbms_lob.createtemporary(bl,true);
    dbms_lob.open(bf,dbms_lob.lob_readonly);
    DBMS_LOB.LOADFROMFILE(bl, bf,dbms_lob.getlength(bf));
    insert into t values (1,bl);
    commit;
    dbms_lob.close(bf);
    dbms_lob.freetemporary(bl);
    end;
    PL/SQL procedure successfully completed.
    SQL>  create index t_idx on t (bl) indextype is ctxsys.context parameters ('filter ctxsys.auto_filter')
    Index created.
    SQL>  declare
       mklob   clob;
    begin
       ctx_doc.filter ('t_idx', '1', mklob, true);
       dbms_output.put_line (substr (mklob, 1, 250));
       dbms_lob.freetemporary (mklob);
    end;
    Oracle® Database
    Release Notes
    11
    g
    Release 1 (11.1) for Linux
    B32001-04
    November 2007
    This document contains important information that was not included in the
    platform-specific or product-specific documentation
    PL/SQL procedure successfully completed.This generates a text only version of your pdf and standard text comparison methods can be applied ....

  • How can i compare two excel files with different no. of records.

    Hi
    I am on to a small project that involves us to compare two excel files. i am able to do it but am struck up at a point. When i compare 2 different .csv files with different no. of lines i am only able to compare upto a point till when the number of lines is same in both the files.
    Eg. if source file has 8 lines and target file has 12 lines. The difference is displayed only till 8 lines and the remaining 4 lines in source lines are not shown.
    Can you help me in displaying those extra 4 lines in source file. I am attaching my code snippet below..
    while (((strLine = br.readLine()) != null) && ((strLine1 = br1.readLine())) != null)
                     String delims = "[;,\t,,,|]";
                    String[] tokens = strLine.split(delims);
                    String[] tokens1 = strLine1.split(delims);
                   if (tokens.length > tokens1.length)
                    for (int i = 0; i < tokens.length; i++) {
                        try {
                            if (!tokens.equals(tokens1[i])) {
    System.out.println(tokens[i] + "<----->" + tokens1[i]);
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + tokens1[i]);
    out.println();
    sno++;
    } catch (Exception exception)
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + "");
    out.println();
    Thanks & Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    A CSV file is not an Excel file.
    But apart from that your logic makes no sense.
    If the 2 files are of different sizes the files are different by definition, so further comparison isn't needed, you're done.
    If you want to compare individual records, you need to compare all records from one file with all records from the other, unless the order of records is important in which case your current system might work.
    That system however is overly complicated for comparing CSV files.
    As you assume a single record per line, and if one can assume those records to have identical layout (so no leading or trailing whitespace in or between columns in one file that's not in the other) comparing records is simply a matter of comparing the entire lines.

  • Compare two pdf files using adobe acrobat through command line

    Does anyone know how to compare two pdf files using adobe acrobat through command line. I want to do this via command line because we want to compare hundreds of file every day through some automated windows tasks.
    If command line option is not available in acrobat, then is it feasible to make use of acrobat javascript API to do this task?
    Any kind of help will be greatly.

    Command-line: Not possible.
    JavaScript: Possible, but very limited. Basically the only thing you can do is simulate clicking the Compare Documents button. The rest has to be done manually.
    However, it *might* be possible to automate this process a bit more using a plugin. Ask over at the Acrobat SDK forum for more information...

  • How to compare two excel files in java ?

    how do i compare two excel files in java.?
    I have two excel files stored on my computer in d: drive.
    Ex:
    D:\\file a
    D:\\file b
    How to compare the contents of these two files and print " files are equal " or "files not equal "

    Javamastermahe wrote:
    I mean i want to print on the console "files are equal " or any message like " both the files match "If this is your requirement, this program satisfies it...
    import java.util.Random;
    public class SuperExcelTester {
        public static void main(String[] args) {
            Random rnd = new Random();
            String[] messages = {
                "files are equal",
                "files are not equal",
                "unexpected error"
            int index = rnd.nextInt(messages.length);
            System.out.println(messages[index]);
    }

  • Compare two text box values????

    Hello All,
    I do have one logic, but not sure where to write it so want your guys help for the same.
    The logic is:-
    if (&P13_NEW_PASSWORD. == &P13_CONFIRM_NEW_PASSWORD.) then
    insert into tbuser (password) values (&P13_NEW_PASSWORD.);
    else
    dbms_output.line_('Both the text boxes should be same!!')
    P13_NEW_PASSWORD and P13_CONFIRM_NEW_PASSWORD are two text boxes, where in above statment I'm comparing two text box values, if yes than insert that values into the DB tables otherwise displaying else messges.
    so can anybody tell me where should i write the above logic to make it work perfect..!!!
    thanks
    regards,
    Kumar

    Kumar,
    I'm glad you asked! Here's a great blog post on a custom auth scheme that hashes passwords:
    http://djmein.blogspot.com/2007/07/custom-authentication-authorisation.html
    I would suggest a few changes to the "get_hash" function. First, the DBMS_OBFUSCATION_TOOLKIT has been deprecated in favor of DBMS_CRYPTO:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_crypto.htm
    http://www.psoug.org/reference/dbms_crypto.html
    DBMS_CRYPTO offers Message Authentication Code (MAC) functions which are keyed hashes. If you use a non-keyed function such as MD5 (which is VERY well known), someone can easily generate a table of all possible passwords within reason and their matching hash, which essentially allows them to get the passwords. MAC functions take in the data (password in this case) and a key. You can probably just use a big random string for your key. Now someone would need to the key as well to generate a hash table. In short, just use DBMS_CRYPTO.MAC where Duncan used DBMS_OBFUSCATION_TOOLKIT.md5.
    Tyler

Maybe you are looking for

  • Server does not recognize my username/password when trying to email photos

    I am trying to mail photo's from my Iphoto's through my email account.  However each time I try to send the pics I get a message that the server does not recognize my username/password.  I have a password for my Bell sympatico account which is the ac

  • Swing image Icons

    Hi all, I used Imageicons(like error, Up, down arrows, etc...) to my swing pplication 2 years back using some image "Jar" file from Sun. but now I didn't find it and fotgot the jar file name. does anyone know the name of the jar file that contains al

  • Safari has turned unusable: crash, crash, crash...

    Suddenly (soon after downloading the massive Apple's 09/28/07 update, which may or maynot be related), my Safari has turned unusable. It seems to be ok upon opening, but attempting surfing results in immediate crashing. First I encounter a Syndicatio

  • Arrangement of marketing attributes

    Hi, we import marketing attributes with elm. There are 4 types of attributes which are very important. The customer wants to have this important one at the top of the list, in the assignment block. The other attributes should stand in the bottom of t

  • Proxy servers and port 80

    I don't know if this will transmit but I am suddenly losing contact with Apple discussions and get a white screen with a reference to Remote proxy servers / port80 / Apple discussions. Would anyone know what is going on and if the problem is my end o