Solved

Merging Text Files

Posted on 1997-11-25
1
165 Views
Last Modified: 2010-04-04
I want to add text from one text (.txt) file into another and discard any duplicates.  The two text files only have one column (e.g., one two words) and a Hard Carriage return.

File#1         File#2
=======================
Value1         Value2
Value2         Value45
Value3         Value46

How do I add the values from file #2 to file#1 and either exclude or delete the duplicates.  If handling teh duplicates is too much trouble, I'd settle for appending the data somehow.
0
Comment
Question by:d4jaj1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
anilms earned 50 total points
ID: 1351839
This is a working example. Assume that there are two memos and the data from the second memo has to be appended to the first memo, but duplicates have to be eliminated. The code would be as follows :

procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
    Exists:boolean;
begin
      Memo1.Lines.LoadFromFile('FirstFile.txt');
      Memo2.Lines.LoadFromFile('SecondFile.txt');

      { For every line/data item in the second file}
      for i:=0 to Memo2.Lines.Count-1 do
      begin
           Exists := False;
           {Search the first file whether data exists or not }
           for j:=0 to Memo1.Lines.Count-1 do
               if Memo2.Lines[i]= Memo1.Lines[j] then
                   Exists := True;
           if not Exists then Memo1.Lines.Add(Memo2.Lines[i])
      end;
      Memo1.Lines.SaveToFile('NewFile.txt');
end;

In the above example, we load the text files containing the data in two Memo components. Then for every item in the second file, we check whether the same entry is there in the first file or not. If it is not there, we add the entry. Finally, as an example, we have saved the combined data in a new file.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question