Solved

Merging Text Files

Posted on 1997-11-25
1
166 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

624 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