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");

Similar Messages

  • 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

  • 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

  • How do I compare these text files (aka spell check)

    I'm having the hardest time figuring out how to get this spell check to work. Basically, I need to open the dictionary.txt file and then another file which will be spell checked. Ignoring case sensitivity, punctuation, and word endings (such as ly, ing, s). And then output to the user the words that were not found in the dictionary. Here is what I have so far (and it is very basic.... there is no attempt to compare yet since I don't know how to approach this). I only have it outputting to a JTextArea what is opened minus punctuation and upper case....
    import java.util.Scanner;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    //  Created Sept 4, 2004
    *   @version 1.0
    *   This program will store dictionary.txt to a String array and
    *   open another text file to be specified by the user of the program.
    *   As the scanner proceeds through the document, it will spell check
    *   and output any (case insensitive) words not found in the
    *   dictionary.txt file.
    public class Spell extends JFrame {
        /** Area to place the individual words in the file */
        JTextArea outputDictionary, outputWord;
    *  Constructor for the class.  Sets up the swing components.
    *  Prompts the user for the files to be processed.  Then invokes
    *  the process method to actually do the work.
    public Spell() {
         // A JTextArea is used to display each word found in the file.
         outputDictionary=new JTextArea("Dictionary List\n\n");
         add (new JScrollPane(outputDictionary));
         //Set the size to 300 wide by 600 pixels high
         setSize(300,600);
         setVisible(true);
            outputWord=new JTextArea("Opened Document\n\n");
            add (new JScrollPane(outputWord));
            setSize(300,600);
            setVisible(true);
        //Prompts user for the dictionary.txt file
        JFileChooser dictionary = new JFileChooser();
        int returnVal = dictionary.showOpenDialog(this);
         if  (returnVal == JFileChooser.APPROVE_OPTION) {
              storeDictionary(dictionary.getSelectedFile());
        //Prompt user to open file to be checked          
        JFileChooser word = new JFileChooser();
        int returnVal2 = word.showOpenDialog(this);
            if (returnVal2 == JFileChooser.APPROVE_OPTION){
                storeOpenFile(word.getSelectedFile());
    public void storeDictionary(File dictionaryFile) {
         String dictionary="";
         Scanner scanner=null;
        try {
            // Delimiters specifiy where to parse tokens in a scanner
           scanner = new Scanner(dictionaryFile).useDelimiter("\\s*[\\p{Punct}*\\s+]\\s*");
        catch (FileNotFoundException fnfe) {
            JOptionPane.showMessageDialog(this,"Could not open the file");
           System.exit(-1);
         while (scanner.hasNext()) {         
              dictionary=scanner.next();
              if (!dictionary.equals(""))
                 outputDictionary.append(dictionary.toLowerCase()+"\n");
            System.out.println("Thank you, your dictionary is stored.");
    public void storeOpenFile(File openFile){
        String word="";
        Scanner scanner2 = null;
        try {
            // Delimiters specifiy where to parse tokens in a scanner
           scanner2 = new Scanner(openFile).useDelimiter("\\s*[\\p{Punct}*\\s+]\\s*");
        catch (FileNotFoundException fnfe) {
            JOptionPane.showMessageDialog(this,"Could not open the file");
           System.exit(-1);
        //stores the words in the opened text file in a String array
         while (scanner2.hasNext()) {         
              word=scanner2.next();
                 if(!word.equals(""))
                        outputWord.append(word.toLowerCase()+"\n");
        System.out.println("Thanks, your file has successfully been opened.");
    public static void main(String args[]) {
       Spell spellck = new Spell();
       spellck.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    Yes, he actually recommends us to use java 1.5. I have revised my code to read into a TreeSet from the dictionary.txt, but I keep getting the following error when I compile:
    Note: C:\Jwork\spell1.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    Finished spell1.
    Also, when I execute, nothing happens. It looks like it is going to try to do something, but the "open" dialog box never opens and no errors pop up. It just sits there executing. Any suggestions??
    here is the code:
    import java.util.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    //  Created Sept 4, 2004
    *   @version 1.0
    *   This program will store dictionary.txt to a String array and
    *   open another text file to be specified by the user of the program.
    *   As the scanner proceeds through the document, it will spell check
    *   and output any (case insensitive) words not found in the
    *   dictionary.txt file.
    public class spell1 extends JFrame{
        JTextArea output = new JTextArea(500,500);
        Set dict = new TreeSet();
        Set file = new HashSet();
        public spell1(){
        Set dict = new TreeSet();
        Set file = new HashSet();
        //Prompts user for the dictionary.txt file
        JFileChooser dictionary = new JFileChooser();
        JFileChooser wordFiles = new JFileChooser();
        int returnVal = dictionary.showOpenDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION) {
         storeDictionary(dictionary.getSelectedFile());
        int returnVal2 = wordFiles.showOpenDialog(this);
            if (returnVal2 == JFileChooser.APPROVE_OPTION){
                storeFile(wordFiles.getSelectedFile());
        public void storeDictionary(File dictionaryFile){
            String dictionary="";
         Scanner scanner=null;
        try {
           // Delimiters specifiy where to parse tokens in a scanner
           scanner = new Scanner(dictionaryFile).useDelimiter("\\s*[\\p{Punct}*\\s+]\\s*");
        catch (FileNotFoundException fnfe) {
            JOptionPane.showMessageDialog(this,"Could not open the file");
           System.exit(-1);
         while (scanner.hasNext()) {
              if (!dictionary.equals(""))
                 dict.add(scanner.next());
            System.out.println("Thank you, your dictionary is stored.");
        public void storeFile(File wordFile){
            String word="";
            Scanner scanner2=null;
        try{
            scanner2 = new Scanner(wordFile).useDelimiter("\\s*[\\p{Punct}*\\s+]\\s*");
        catch (FileNotFoundException fnfe){
            JOptionPane.showMessageDialog(this,"Could not open the file");
            System.exit(-1);
            while(scanner2.hasNext()){
                if(!word.equals(""))
                    file.add(scanner2.next());
        public static void main(String args[]){
            spell1 spellck = new spell1();
            spellck.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

  • Compare with text file

    Is it possible to do a line by line compare with the data in a text file and print the required data?
    BufferedReader readCode = new BufferedReader(new FileReader("code.txt"));
    String code = readCode.readLine();
    while(more) {
    System.out.print("Code:");
    String productCode = in.readLine();
    while (code != null){
         code = readCode.readLine();
         if (!(productCode.equals(code) || productCode.equals(code) || productCode.equals(code) ||productCode.equals(code) || productCode.equals(code) || productCode.equals(code) || productCode.equals(code) || productCode.equals(code))){
         // Goes back to the next loop interaction. Skiping the rest of the loop below
         System.out.println("Invalid product code. Check the product code again");     
         continue;
    productTemp[j] = productCode;
    do{
         /*Keep asking for a quantity until some valid value is entered
         System.out.print("Quantity[0-100]:");
         productQuantity = Integer.parseInt(in.readLine());
    }while(productQuantity > 100 || productQuantity < 0);
    quantity[k]=productQuantity;          
    totalQuantity = quantity[k] + totalQuantity;
    j++;
    k++;
    noOfItems++;          
    }     i cant seem to compare the user input code with the code in my textfile.i am stuck here...can somebody enlighten me?

    nvm...thanks for ur help anyway..i try others
    ways..save ur remarks for other pplThis is a public unmoderated forum. If you don't want remarks, don't post.
    Besides, if you're not willing to describe your problem in better detail, what kind of "help" do you expect? It's not like you've entered a forum full of psychics. Your problem is unclear. You've been given suggestions. If you have a more specific question, feel free to ask. Otherwise, feel free to continue floundering about.
    Good luck.

  • 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 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

  • How can i feed a text file into a Hashtable?

    Hi,
    im working on my third year project, im new to java and am struggling a little with writing the code.
    I need to feed a text file into my program and insert it into a hashtable. I presume i'll be using an input stream to feed the file in, how do i go about placin the text file into a hashtable??
    please help!

    ok, so im trying to code an authorship attribution
    program. the first part of the program need to
    compare a text file A (list of words), with another
    two text files B and C. Compare how? Do you want to know how many times certain words from list A appear in files B and C?
    The words in list A will first be compared to those
    in list B and than list C. I was wondering if there
    was a way of inserting file A,A Map is a list of key/value pairs, so what do you mean by inserting here? What are you inserting? What would the keys and values here be?
    followed by B,
    comparing the two files.....than inserting file C and
    comparing it with A??
    Does this make sense??Not quite, but it might just be me.

  • Upload text files

    Hi,
    Can anyone help me with the source code to upload and compare 2 text files?
    it urgent plz.
    regards.

    DATA: I_TAB TYPE STANDARD TABLE OF TY_ITAB WITH HEADER LINE.
    DATA : GFILE(150).
    DATA: G_FILE(150).
    DATA: PATH(100).
    DATA: DATE(8), DATE1(6).
    DATA: RECORD TYPE STRING,
          FILE TYPE STRING.
    DATA: L_FILETAB     TYPE FILETABLE,
          L_FILETAB_H   TYPE FILETABLE WITH HEADER LINE,
          INITIAL_DIR_PATH TYPE STRING,
          L_RC          TYPE I.
    SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    PARAMETERS: FNAME TYPE LOCALFILE OBLIGATORY.
    SELECTION-SCREEN: END OF BLOCK B1.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR FNAME.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
        EXPORTING
        WINDOW_TITLE            = 'Select the Asset Master Data file'
       DEFAULT_EXTENSION       =
       DEFAULT_FILENAME        =
        FILE_FILTER             = 'Text Files (.TXT)|.TXT|'
        INITIAL_DIRECTORY       = INITIAL_DIR_PATH
          MULTISELECTION          = SPACE
       WITH_ENCODING           =
        CHANGING
          FILE_TABLE              = L_FILETAB
          RC                      = L_RC
       USER_ACTION             =
       FILE_ENCODING           =
        EXCEPTIONS
          FILE_OPEN_DIALOG_FAILED = 1
          CNTL_ERROR              = 2
          ERROR_NO_GUI            = 3
          NOT_SUPPORTED_BY_GUI    = 4
          OTHERS                  = 5
      IF SY-SUBRC <> 0.
        WRITE:/ 'Error while selecting the input file'.
      ELSE.
        LOOP AT L_FILETAB INTO L_FILETAB_H.
          FNAME = L_FILETAB_H-FILENAME.
          EXIT.
        ENDLOOP.
      ENDIF.
    START-OF-SELECTION.
      PERFORM READ_FILE_DATA.
    *&      Form  READ_FILE_DATA
          text
    -->  p1        text
    <--  p2        text
    FORM READ_FILE_DATA .
      DATA: VFILE TYPE STRING.
      DATA: FL(1).
      VFILE = FNAME.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
         FILENAME                      = VFILE
         FILETYPE                      = 'ASC'
         HAS_FIELD_SEPARATOR           = 'X'
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
        DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
        TABLES
          DATA_TAB                      = I_TAB
       EXCEPTIONS
         FILE_OPEN_ERROR               = 1
         FILE_READ_ERROR               = 2
         NO_BATCH                      = 3
         GUI_REFUSE_FILETRANSFER       = 4
         INVALID_TYPE                  = 5
         NO_AUTHORITY                  = 6
         UNKNOWN_ERROR                 = 7
         BAD_DATA_FORMAT               = 8
         HEADER_NOT_ALLOWED            = 9
         SEPARATOR_NOT_ALLOWED         = 10
         HEADER_TOO_LONG               = 11
         UNKNOWN_DP_ERROR              = 12
         ACCESS_DENIED                 = 13
         DP_OUT_OF_MEMORY              = 14
         DISK_FULL                     = 15
         DP_TIMEOUT                    = 16
         OTHERS                        = 17
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " READ_FILE_DATA

  • 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 :-)

  • How to load text files in GUI

    plz tell me .. how to load and compare two text files using file popup's . example file i have attached..
    Attachments:
    testW_FF.txt ‏2 KB

    I don't understand whether your question is on how to load text files or how to show them on a panel or how to compare them... or all aspects together!
    The first operation (loading the file) can be accomplished with functions included in the Formatting and I/O Library like OpenFile, ReadFile and so on; with a file like yours even FileToArray could be an option.
    How to show the data on screen is heavily dependent on what you intend to do with them: data can be shown in textboxes, listboxes, tables or graphs so... what do you want to do?
    The same applies with comparison: without additional details is difficult to give you the proper hint.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How to compare two files in java & uncommon text should print in text file.

    Hi,
    Can any one help me to write Core java program for this.
    How to compare two files in java & uncommon text should print in other text file.
    thanks
    Sam

    Hi All,
    i m comparing two HTML file.. thats why i am getting problem..
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class textmatch{
    public static void main(String[] argv)
    throws Exception{
    BufferedReader fh =new BufferedReader(new FileReader("internal.html"),1024);
    BufferedReader sh = new BufferedReader(new FileReader("external.html"),1024);
    String s;
    String y;
    while ((s=fh.readLine())!=null)
    if ( s.equals(y=sh.readLine()) ){    
    System.out.println(s + " " + y); //REMOVE THIS PRINTLN STATEMENT IF YOU JUST WANT TO SHOW THE SIMILARITIES
    sh.close();
    fh.close(); }
    thanks
    Sam

  • Compare data from 2 text files and output match

    Hi all,
    I need some advice.
    Firstly in BinaryCode.txt the data is as such:
    Replace BinaryCode0 1 0 0 0 0 0 0 0 0
    Replace BinaryCode0 1 0 0 0 0 0 0 0 1
    Replace BinaryCode1 1 1 1 0 1 1 1 1 1
    Replace BinaryCode1 1 0 0 0 0 0 0 0 0
    the first line in the text file is the header. So I need to check if the names in the second column (BinaryCode0 or BinaryCode1)appear in the Timed_Sets.txt file.
    The data in Timed_Sets.txt is as such:
    BinaryCode0,6,40,.........................
    BinaryCode0,7,40,.........................
    BCName1,0,20,.............................
    BCName1,1,20,............................. 
    For example since  BinaryCode0 is a match I will output the entire row in Timed_Set.txt to another array. 
    I have been working on a program but I don't get the expected output. 
    The text files and the VI are attached.
    I appreciate your kind assistance in the matter.
    Thank You
    Regards
    kart 
    Solved!
    Go to Solution.
    Attachments:
    BinaryCode.txt ‏1 KB
    compare text files.vi ‏15 KB
    Timed_Sets.txt ‏2 KB

    If I understood correctly what the output should be then what you basically need to do is to walk through the column in BinaryCode.txt and for each unique value pull out the corresponding rows from Timed_Sets.txt. There's a variety of ways to do this, depending on how much data you have and whether or not you can use any kind of prior knowledge as to the actual file content (such as the names of the keys being searched). Attached is one way. Modify as needed.
    Attachments:
    compare text files MOD.vi ‏27 KB

  • Compare string in different line in text file

    I am new to java and I need a simple example to compare string in file text by for loop
    file.txt:
    A78802 D06VAIS060253113 WKNEUP751346577450
    A77802 D06VAIS060253113 WKNEUP751346577450
    A76802 D06VAIS060253925 WKNEUP751346577450
    A78802 D06VAIS075253698 WKNEGE226375082796
    A73802 D06VAIS116253222 WKNEFB227345305299
    dataString = TextIO.getln();
    A=dataString.substring(25,42);
    B=dataString.substring(195,203);
    C=dataString.substring(171,186);
    I WANT COPMPARE IN LINE 1 POSITION 20 TO LINE 2 POSITION 20 BY LOOPS ALL THE LINE IN TEXT FILE

    what have you tried so far?
    Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, either use the "code" button at the top of the forum Message editor or place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
    &#91;/code]

Maybe you are looking for