Comparing file content

Good morning,
I am trying to determine if records in one text file are a subset of records in a second file.
For example the 1st file(A) contains the names
jan
eva
john
And the second(B) contains
eva
richard
jan
paul
I've started by formulating the problem in simple English:
"If all file A contents IN file B return TRUE
else return FALSE"
The code below compiles and runs. The problem is that it produces faulty results.
When comparing A to B, for example it returns TRUE. I'm guessing this is because the loop is exited as soon as the condition evaluates to TRUE, which leaves the file only partially read.
Comparing B to A yields FALSE as it should.
I imagine that I'll need to modify the loop so it first reads all the records in the first file and then compares them to the records in the second file.
So, my question, finally ;-), is:
can anyone give me some tips on how to adjust this code?
public boolean containsSame(String filenameb) throws IOException
     Stream a = new Stream (filename, Stream.READ);
     Stream b = new Stream (filenameb, Stream.READ);
try
     String stra;
     String strb =b.readString();
     while((stra=a.readString()) != null)
     if(stra.equals(strb))
          System.out.println("All the names in " + filename + " are found in " + filenameb);
          return true;      //Problem seems to be here
                                   // when condition = true loop appears to end
                                   // leaving (possibly) part of the file unread
catch (EOFException e)
          System.out.print("End of file");
          //System.out.println();
          System.out.println("All the names in " + filename + " are NOT found in " + filenameb);
          return false;
}

Call it inner and outer loops is not really good. The programming term is nested loops.
Examples:
// nested while loop
// outer loop
while (true) {
    // inner loop
    while (true) {
// nested do...while loop
// outer loop
do {
    // inner loop
    do {
    } while (true)
} while (true)
// nested for loop
// outer loop
for (int i = 0; i < length; i++) {
    // inner loop
    for (int j = 0; j <= i; j++) {
}Of course you could have any number of loops inside a loop. An you could have any combination of them.
An example:
for (int i = 0; i < length; i++) {
    while (true) {
}

Similar Messages

  • Can we compare file contents of two files in the Application server?

    Hi,
    A file is generated daily to the application server. and i need to compare the generated file to the file generated on the previous day and prepare a report.
    Can we compare file contents of two generated files present in the Application server?
    If there is any alternative, please suggest.
    regards
    cs

    yes we can compare if the app server is Unix.
    cmp compare two binary files and report if different
    cmp is silent if the files are the
         same;
    if they differ, the byte and line number at which the first
    difference occurred is reported.
    REPORT ZUNIX line-size 400
                    no standard page heading.
    data: unixcom like   rlgrap-filename.  
    unixcom = 'cmp file1 file2'.
    data: begin of tabl occurs 500,
            line(400),
          end of tabl.
    data: lines type i.
    start-of-selection.
      refresh tabl.
      call 'SYSTEM' id 'COMMAND' field unixcom
                    id 'TAB'     field tabl[].
    "if the files are different then you will some content in tabl
    Regards
    Viajy  Babu Dudla

  • Script to Compare File Contents in Two Folders and List Differences?

    I've looked through the Forum but can't find anything that seems quite to address my problem--and I'm really new to AppleScript, so please forgive me if this is a dumb question.
    I burn a great many files of varying kinds (InDesign, Illustrator, Photoshop, PDF, etc.) to DVD everyday as part of my job. It happens not infrequently, though, that files drop out in the process and don't make it to the disk, with the result that I get calls from Manufacturing saying that I've screwed up and that random files X, Y, and Z are not on the disk that I sent.
    I've tried various ways to failproof my burning routine, but utlimately, it seems like something still slips through sometimes--that is, the files are definitely in by Source Folder, but sometimes they don't leap the chasm to the disk. And since there can be several hundred files, it can be difficult to know at a glance if something is wrong.
    It would be extremely helpful if there were a script that I could run to compare the contents of the folder source on my desktop (just say its called "Source Folder") with the contents of a disk I have just burned (whose name might vary, but whose folder structure is a duplicate of the subfolders in "Source Folder" that I have burned to disk. All I need the script to tell me is if there are files in my desktop Source Folder than are not on the burned disk).
    Is this possible? I'd appreciate any help anyone could offer--right now, I'm printing up the disk directory and a list of the files from my desktop Source Folder and comparing them line for line, and my soul is dying.
    Please help!

    This can be pretty easily hacked together using a combination of AppleScript and shell scripting.
    There's a shell command diff that can tell if two directories are the same or not. You can use AppleScript to put a nice front-end on it, like:
    set src to (choose folder with prompt "Select the source directory")
    set dst to (choose folder with prompt "Select the destination directory/disk")
    try
      do shell script "diff -rq " & quoted form of POSIX path of src & space & quoted form of POSIX path of dst
    on error theErr
      display dialog "The following differences were found:" & return & return & theErr
      return
    end try
    display dialog "Directories match. No differences found"
    It's quick and dirty, but should get you started. It runs the diff command which triggers the 'on error' code if there are any differences. The script then reports the differences and exits. If there are no differences the 'on error' code is skipped and you get the all clear message.

  • Compare file contents

    Usually I take my photos in RAW format, and a matching jpeg is produced automatically by the camera software. The file names are identical except for the extension. Occasionally however for speed of working I will take some photos on the card in jpeg only -no matching RAW.
    I have a workflow that separates the RAW and jpeg files into separate folders, but I can't seem to find a method to compare folder contents so as to easily and quickly identify the "lone jpegs" (i.e. those that have no matching RAW). The comparison could of course be done before or after separation - whichever is easiest.
    Anyone tried this or similar - it seems to be not currently possible (a glaring omission IMO) but maybe there's a work round that someone's found and would share?
    Thanks in advance for any responses!

    I don't know about automator, but it's an easy one for the shell:
    cohi@tigger:/tmp> ls raw
    1.raw 2.raw 4.raw
    cohi@tigger:/tmp> ls jpg
    1.jpg 2.jpg 3.jpg 4.jpg
    cohi@tigger:/tmp> ( find jpg -name "*.jpg" ; find raw -name "*.raw" ) | sed 's/raw/jpg/g' | sort | uniq -c | grep " 1" | cut -b 9-
    jpg/3.jpg

  • Copying & comparing File Content

    I have Written a java code, which is taking the content of one file and copying it in to another file, by replacing its content. I want that to get appended in the file I am copying it in. I want to compare each line of first file to the second .txt file. And if it seems to be the same, then discard that line but copies all other line.
    Is it possible???

    yes

  • Is there a way to compare the contents of a library by comparing itl files or some other files?

    Is there a way to compare the contents of a library by comparing itl files or some other files?
    I need to compare the contents of my current library to one that existed 2 months ago but ALL I have is the itl file from 2 months ago.  Can this be done?

    You are correct, many people have noticed over the years that Sound Check does not work as advertised.
    A more effective approach is to treat the files with a 3rd party volume normalization program. Although I have not personally used it, many users on this Forum have reported good results from an inexpensive program called iVolume.

  • Upload 2 files and compare its contents

    Hi guys,
    I want to upload 2 files in SAP and compare its contents.
    How am i going to do that?
    Please provide sample code... Thanks a lot!
    rgds,
    Mark

    Hi Mark,
    I expected to use this code, once u can try this code.
      OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
      IF sy-subrc = 0.
        LOOP AT gi_output1 INTO gwa_output1.
          CLEAR lv_string.
          CONCATENATE gwa_output1-matnr
                      gwa_output1-maktx
                      gwa_output1-werks
                      gwa_output1-bmeng
                      gwa_output1-posnr
                      gwa_output1-idnrk
                      gwa_output1-ojtxp
                      gwa_output1-mngko
                      gwa_output1-mmein
                      gwa_output1-flag
                      INTO lv_string
                      SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
          TRANSFER lv_string TO lv_filename.
          IF sy-subrc <> 0.
            MESSAGE e006(zpdm).
          ENDIF.              "if sy-subrc <> 0.
        ENDLOOP.
         OPEN DATASET lv_filename FOR appending IN TEXT MODE ENCODING DEFAULT.
      IF gi_output2[] is not initial.
        LOOP AT gi_output2 INTO gwa_output2.
          CLEAR lv_string.
          CONCATENATE gwa_output2-matnr
                      gwa_output2-ojtxb
                      gwa_output2-werks
                      gwa_output2-bmeng
                      gwa_output2-posnr
                      gwa_output2-idnrk
                      gwa_output2-ojtxp
                      gwa_output2-mngko
                      gwa_output2-mmein
                      gwa_output2-flag
                INTO  lv_string
           SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
          TRANSFER lv_string TO lv_filename.
          IF sy-subrc <> 0.
            MESSAGE e007(zpdm). " WITH text-006.
          ENDIF.           "if sy-subrc <> 0.
        ENDLOOP.
      ENDIF.

  • Compare SQL file tables as a file content VS Documentum or Alfresco

    Hello - Documentum & Alfresco are 2 examples of Document Content Management (file repository, workflows, notifications, etc), I am interesting in the file content management where system provides file repository and some extra features like check in
    / check out and versioning. Does anyone have tried to replace a file repository with SQL file tables?

    You can use SQL Filetables for storing files as well as doing modifcations etc. for getting versioning you can enable change management or implement audit triggers in them.
    Here are some helpful links
    http://visakhm.blogspot.in/2012/07/working-with-filetables-in-sql-2012.html
    http://visakhm.blogspot.in/2012/07/triggers-on-filetables-in-sql-2012.html
    http://visakhm.blogspot.in/2013/09/implementing-transaction-over-file.html
    Check in checkout will not be available by default. You may need to implement it using some flags. My question is why cant you go for a versioncontrol software then like TFS? why reinvent the wheel?
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to print list of file contents of a HDD

    Hi Everyone!
    (Sorry for using a quote---The copy/paste  from my old Text Editor does not work here.... why not?  Only if I am doing a quote)
    I have a Mac G4 (yes) with Tiger 10.4.11 (yes still)  and I have two backup drives.... They should be evenly "filled" but there is over 26 GB difference so that one is going to be running out of space sooner than I want it to.  I have 100's of files... I need some program that works under Tiger to either:
    1. Print the contents of the HDD (the file names/sizes, etc---there is something that does this in Windows, why not Mac?).
    or
    2.  A program that compares the contents automatically between the two HDD's.  Again I have used one on PC's but its really old and company no longer makes it for PC's.  Is there one for Mac? I have no idea how to express it to look it up.  (I never have both of the HDD's all hooked up by Firewire at same time---afraid of overloading old Mac).... so only if there is a program that does this working under Tiger would I then come back here to ask a question for how to get the two drives hooked up to compare the contents and find out what is taking up extra space.
    Mostly the drives have iPhoto items in it so it could be simply a double-entered iPhoto Roll/Album---but never thinking I'd have to compare them---most of the titles begin the same exact way---too difficult to go over unless I can cross off a printed sheet to compare the two drives---or have a computer do that for me.
    Any suggestions? 
    Thanks for reading me!
    Mac_Help

    Tex-Edit Plus
    Universal Version 4.10.2
    Mac OS 10.4 thru 10.10
    File Size: 10703K
    Tex-Edit Plus
    PPC Version 4.9.8
    Mac OS 10.1 thru 10.3
    File Size: 3970K
    Tex-Edit Plus
    Classic Version 4.1.3
    Mac OS 7 thru 9
    File Size: 5294K
    Tex-Edit
    Legacy Version 2.7.2
    Mac OS 6
    File Size: 257K
    Tex-Edit Plus (beta)
    Pre-release Version 4.10.3 b2
    Mac OS 10.4 thru 10.10
    File Size: 10705K
    Hi BDAqua!
    Thanks for the links!  I'll take both of them!  (If they fit in my old HD)
    Explaining a bit more----I'm using a "PC" to write these questions (yes I have a bunch more) about the old Tiger Mac 10.4.11 G4.
    I only have working TenFourFox7450 and OmniWeb as my only two ways to get online now.  Very slow.  Very limited windows I can open at once to compare or research things, so I'm back on the PC to do all that and copy and paste quotes here for you. Seems once I pass the first question, the only thing Quote does is quote your message---I managed to cheat a bit and got what I wanted to copy from the Tex-Edit page to show up instead..
    You recommended that I choose Tex-Edit Plus PPC Version 4.9.8---but as you see above that is only for 10.1 to 10.3 versions..... is there some reason why the  Tex-Edit Plus (Beta) above is bad for me?  It says 10.4 or higher.
    Or why not use the "Universal" Tex-Edit Plus?  Seems that covers 10.4?
    I got both TextWrangler and Tex-Edit Plus "Universal" Edition to work on the Mac!
    Page numbers on the Tex-Edit!  Wow!
    Thanks!
    Also (saving address for later)    that page has Eliza on it.. which I had long time ago.... but lost somewhere among all the other programs. So thanks for showing me I can find and add it in later on when I get more space on HDD
    I'll type now my reply to your earlier message/posting!
    Mac_Help

  • How can i compare the contents of two folders ?

    how can i compare the contents of two folders and find out which files are in one but not in the other?? Knowing how to do this would be the best thing ever, especially when dealing with a large number of files. Often, for instance, I'm dealing with a large number of images, processing them, and saving the retouched ones to a new folder, and need to check that they are all there. If there are say three files missing in the second folder (out of say a hundred in total) being able to automate the process of elimination would be very useful. Please help!!!
    B

    I really wish I knew the answer to this. I work between two macs, a G5 and MacBook Pro when I'm on the go. Each time I move from one to the other I have to copy all my files to the computer I'm going to work on, so I end up with the same files being duplicated. It's not a problem if it's not much data but in my case the it can be to 30GB, mostly graphics files, photoshop, motion, final cut pro, etc.
    There's has got to be a way automator can make a comparison between two folders to sort out what's changed and what's remained the same. It would be nice also if this feature could be done globally on the hard disk using spotlight's technology to stop files being duplicated in places you didn't even know about and taking up valuable disk space. I'm not sure how this could be done.
    Any bright ideas Apple?

  • Comparing folder contents

    Hi all
    This is a it embarrassing to be honest, but I find myself in a bit of a filing based mess.
    The background - skip if you don't want to hear bleating about how poor my filing is
    In a fit of idiocy I have made many duplicate folders (including multiple duplicates of content such as my 15,000 image photo library) to ensure safety of the files therein. I've done this a lot of the last three years, and find myself now in a position where I haven't got a clue what is where, and what is up-to-date.
    I have 600G odd drive space.
    I have 1 50G iMovie project, a large iPhoto library and quite a bit of music.
    I have 30G free - mainly because of my completely slap-dash method of 'backing up' - which I realise I'm not actually doing - and also because I have a lot of files copied here from other desktops, laptops and iPods.
    The question
    Obviously I have a task on my hands to sort this lot out. What would make my life a lot easier would be an application that compares the contents of two folders, and shows me where they differ - this way I am hoping to be able to completely erase great swathes of files without having to comb through them making sure I don't loose an iSight screen grab of my son smashing his Buzz into the screen or some-such. Anyone know of anything that would make my life easier here?
    I used to be fairly ordered about where I put files, and how my folders are structured, honest.
    Thanks for any help / advice / smacks on the back of the hand...
    Flea

    Arctic
    Well you have a nice project to pass the Winter nights!
    Do a search on http://www.macupdate.com using 'duplicate' as the search term. This will provide you with quite a few apps which claim to search for and remove duplicate files. Read and make your choices there.
    However, do not trash any file without reviewing it yourself. There are some things a computer cannot do, and recognising emotionally valuable items is one of them.
    Have fun.
    Regards
    TD

  • Get modified date inside the File content of CM

    hi,
    In CM I have uploaded a file and have set the permission to modify the file to a group of users.Now when each and every time any user modifies the file content I want to have the modified date inside the updated file.
    How can i achieve this?.....
    Please help.....
    Thanks in advance,
    shami.

    Hi All,
    @Parvathy:There is no such property on your files, you should create one in your filter and depending on this custom property your filter should decide if a document update is required or not.
    As already said follow this:
    You have a content filter which can do updates to these files:
    -- Content filter sets a custom property new_modifieddate on each resource after updating resource. (new_modifieddate==cm_modified of resource)
    -- It compares new_modifieddate with cm_modified of resource to determine if it should update the resource with cm_modified.
    @Shami: Use some logging in your Filter code, so that you can make sure your code is being executed. One more way is to dubug you code by setting break points in NWDS (Ofcourse the server should be in debug mode for this option).
    logging :
    http://help.sap.com/saphelp_nw2004s/helpdata/en/a0/58db515b95b64181ef0552dc1f5c50/frameset.htm
    debug:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/5d/31e540b1278631e10000000a1550b0/frameset.htm
    Greetings,
    Praveen Gudapati

  • CompareTo method to compare files

    I have to compare each line from two files and say whether the lines are different or not. I don't exactly understand how to use the compareTo method in this type of situation. I'd appreciate any help.
    import java.util.*;
    import java.io.*;
    import java.net.*;
    import java.util.StringTokenizer;
    public class FileComparer
    public static void main (String[] args)
    String line, file="http://condor.depaul.edu/~jpetlick/extra/224/display.txt";
    String line2, file2="http://condor.depaul.edu/~jpetlick/extra/224/display2.txt";
    int lineCount = 0, wordCount = 0, lineCounter = 0;
    try
    URL URLfile = new URL (file);
    InputStream input = URLfile.openStream();
    BufferedReader buffer = new BufferedReader(new InputStreamReader(input));
    line = buffer.readLine();
    URL URLfile2 = new URL (file2);
    InputStream input2 = URLfile2.openStream();
    BufferedReader buffer2 = new BufferedReader(new InputStreamReader(input2));
    line2 = buffer2.readLine();
    while (line != null)
    if (line != line2)
    System.out.println("at Line " + lineCounter);
    System.out.println("DISPLAY.TXT " + line);
    System.out.println("DISPLAY2.TXT " + line2);
    lineCounter++;
    StringTokenizer st = new StringTokenizer(line);
    wordCount += st.countTokens();
    lineCount++;
    line = buffer.readLine();
    line2 = buffer2.readLine();
    System.out.println("\nA total of " + lineCounter + " were different between DISPLAY.TXT and DISPLAY2.TXT");
    System.out.println("DISPLAY.TXT contains:");
    System.out.println("\nTotal number of lines: " + lineCount);
    System.out.println("Total number of words: " + wordCount);
    catch (FileNotFoundException exception)
    System.out.println("The file " + file + " was not found.");
    catch (IOException exception)
    System.out.println(exception);
    }

    Change the lineif (line != line2)to if (!line.equals( line2))since strings are immutable in java "line != line2" will alwais evaluate to false in your case.
    equals actually compares the contents of the string.
    Kurt.

  • Can't compare files in VS 2012

    Hello,
    Randomly i can't compare files anymore in VS 2012 and only a restart of VS helps.
    The error message is:
    Microsoft Visual Studio
    One or both of these files are not text files and cannot be opened in the comparison window.
    C:\Users\wfuerst\AppData\Local\Temp\TFSTemp\vctmp23076_218344.sln
    C:\t\E\src\EFA_Integration\Solution\DefaultCustomer\DefaultCustomerSolution.sln
    The contents of the two files are different.
    OK  
    Whats wrong here and how can i fix this?
    Thanks,
    Wolfgang

    Same issue here. Can't find a pattern to reproduce but it occurs and only a VS2012 restart will let you compare any file again.
    I have VS2012 running against a TFS2012, TFS 2010 power tools installed.
    3. Can you open the files in notepad?
    YES, both
    4. Do you compare a local file and a server file?
    YES, Source path is filled out with the server location, Target path with the local
    5. Check the file in temp folder when you get this error.
    Checked, I can use winmerge effectively between the same 2 files VS is complaining about
    6. Is there any detail event log relate to this issue?
    No, couldn't find anything on the event logs

  • File content comparison

    hi all,
    how to compare the contents of two files are same or not.Will FileReader will do ?is it so time consuming?any other alternative.
    note:
    both the file may have large numbers of data's, say like 50,000 records.
    Barath v

    File Reading is done in Bytes. U need to Store the Bytes and probably do the Comparison with the Bytes read from other File.
    Hope it helps,
    Cheers,
    Manja

Maybe you are looking for