473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Compare two files

Hi folks,

Every 14 days a production file is read into a SQL-server. Each line
must be handled individually and managed by code.

The last file contains approx. 610,000 lines and gains +40,000 every
14 days.

Each line in the file is unique. Unfortunately, it is not possible for
the lines to have the same order from file to file, so I can't have
any marker.

Today I read the first ten characters of each line, since these make
up an ID telling me if this record already exist in my
SQL-server-table. But as you can imagine looking up +600,000 ID's
takes a tremendous amount of time, even though indexed.

So, what I was wondering: is it possible for me to compare the two
files in some fancy way? Any line in NewFile not in OldFile, write
these to a third file..?

Or perhaps something entirely different?

Regards /Snedker
Dec 16 '05 #1
5 1534
Morten Snedker wrote:
Hi folks,

Every 14 days a production file is read into a SQL-server. Each line
must be handled individually and managed by code.

The last file contains approx. 610,000 lines and gains +40,000 every
14 days.

Each line in the file is unique. Unfortunately, it is not possible for
the lines to have the same order from file to file, so I can't have
any marker.

Today I read the first ten characters of each line, since these make
up an ID telling me if this record already exist in my
SQL-server-table. But as you can imagine looking up +600,000 ID's
takes a tremendous amount of time, even though indexed.

So, what I was wondering: is it possible for me to compare the two
files in some fancy way? Any line in NewFile not in OldFile, write
these to a third file..?

Or perhaps something entirely different?

Regards /Snedker

I recommend importing the text file into a temp table, then run a sql
compare statement between the two tables, do the work that needs to be
done, then empty the temp table. Let SQL do the work instead of line by
line code.

Tom

Dec 16 '05 #2
hi morten,
for finding new row, ultimately you have to traverse through all the
rows. this can not be avoided. the solution "tomb" provided is good
enough to save you from writing the comparision logic on the front
side. but ti will take time to upload all the rows into the database.
if you can compromise on time than there is no issue. and even i would
prefer that way. now the problem of uploading lines into the database
is little bit tuff call as uploading these many lines is bit costly
affair. anyways do let me know if you have any other issue.

Dec 16 '05 #3
Morten,

There is no instruction Every New Line in Old file.

And if it was there, it would probably not go faster than that you write it
yourself, you can use all the same Net instructions as are used after the
cover.

You have in my opinion two options and both are using the DefaultView of
your tables, from which you have set the Sort property.

In my opinion is the most simple just to go through the newest table and use
the dataview.find. If you don't find it (-1), than it is new.

http://msdn.microsoft.com/library/de...sfindtopic.asp
(be aware that there are two methods, one for with one key and another with
more keys)

An other option is going sequentially through both tables in the classic
matching way.

However I would first try the find, mostly these operations with less than
millions of rows takes much less than a second.

An alternative if you are able to that, is of course setting a
timestampcolumn in your SQL database, however I have assumed that this is
not possible..

I hope this helps,

Cor

"Morten Snedker" <mo****@dbconsult.dk> schreef in bericht
news:5l********************************@4ax.com...
Hi folks,

Every 14 days a production file is read into a SQL-server. Each line
must be handled individually and managed by code.

The last file contains approx. 610,000 lines and gains +40,000 every
14 days.

Each line in the file is unique. Unfortunately, it is not possible for
the lines to have the same order from file to file, so I can't have
any marker.

Today I read the first ten characters of each line, since these make
up an ID telling me if this record already exist in my
SQL-server-table. But as you can imagine looking up +600,000 ID's
takes a tremendous amount of time, even though indexed.

So, what I was wondering: is it possible for me to compare the two
files in some fancy way? Any line in NewFile not in OldFile, write
these to a third file..?

Or perhaps something entirely different?

Regards /Snedker

Dec 16 '05 #4
On 15 Dec 2005 21:50:36 -0800, "Lucky" <tu************@gmail.com>
wrote:

First of all thanks to all of you for your time and input!

When you say "comparison logic", do you mean comparing the current
import with the previous import? Through joins?

If so, I fear the performance with a maximum length of a line at 1200
characters...

Or do you mean something else with "comparison logic" ?

Regards /Snedker
hi morten,
for finding new row, ultimately you have to traverse through all the
rows. this can not be avoided. the solution "tomb" provided is good
enough to save you from writing the comparision logic on the front
side. but ti will take time to upload all the rows into the database.
if you can compromise on time than there is no issue. and even i would
prefer that way. now the problem of uploading lines into the database
is little bit tuff call as uploading these many lines is bit costly
affair. anyways do let me know if you have any other issue.


Dec 16 '05 #5
well, i mean comparision value by value. than u'll come to know which
one is new

Dec 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nicolas Fleury | last post by:
Hi everyone, Is there a way to compare recursively two objects (compare their members recursively)? I'm only interested in equality or non-equality (no need for lower-than...). Thx and...
1
by: Frank | last post by:
Hi, is there a way to use XSL to compare two XML files to verify if a "record" in an XML file has changed of parent in another XML file ? I am trying to implement a template in an XSL stylesheet...
8
by: Vincent | last post by:
has any one seen a program to compare mdbs'. I have ran into a few of them, but none seem to really do that job. Basically what I need to do is, take 2 access mdb's and check the differences...
2
by: SP | last post by:
Hi All, I need to compare two files line by line and copy the differing lines to a new files. I.e. Compare file1 and file2 line by line. Copy only differing lines to file3. I tried a couple...
5
by: drabee | last post by:
Please help 2 things: 1-I need c# code to compare 2 audio files .or any other .net code 2-code to receive bluetooth file from mobile and save it using .net code
0
by: bobbymusic | last post by:
In my form I have two rich text boxes.In both of them I put two different text files(.txt or .rtf).I looking for some code to compare them, and to have the result as marked differences into the...
6
by: yinglcs | last post by:
Hi, i have 2 files which are different (1 line difference): $ diff groupresult20070226190027.xml groupresult20070226190027-2.xml 5c5 < x:22 y:516 w:740 h:120 area: --- But when I use the...
8
by: Perl Beginner | last post by:
I am new to Perl and new to this site. I have the same question that I keep seeing, but not finding an answer…why doesn’t the compare function work? I’ve been going at this for a while. My code is...
1
by: =?Utf-8?B?RGFuaWVsIERpIFZpdGE=?= | last post by:
II want to compare how many seconds there are between files. If the files are within a 1 - 10 second range I want to copy them to their own folders. What I have so far is a couple methods that take...
12
by: blackirish | last post by:
Hi all, I am trying to merge 2 XML files that first of all i need to compare nodes of both files according to 2 attributes in the nodes. If those 3 attributes are equal, i need to replace the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.