Visit Our UNIX and Linux User Community


Comparison of 2 files in UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Comparison of 2 files in UNIX
# 22  
Old 11-13-2007
Quote:
Originally Posted by Dana Evans
file1 and file2 have column values of a specific oracle table exported and stored in Unix system
Most SQL tables have a key field or fields. Normally the key field would be used to identify and match the record to determine if it has changed. But from your requirement, this is not what you are looking for.

Also, normally SQL queries do not guarantee the order of records unless the order by clause is used. So, without order by, the same query executed twice could, theoretically, return the same records in two totally different orders.
# 23  
Old 11-13-2007
Quote:
Originally Posted by kahuna
So, without order by, the same query executed twice could, theoretically, return the same records in two totally different orders.
True. Even if the files are not ordered it would be possible to pipe them through "sort" (man sort) to get them sorted prior to searching them. This would limit the search-effort too, because at some point one could be sure that no matching record will follow.

bakunin
# 24  
Old 11-14-2007
Hey bakunin n kahuna
thanks a ton
i think i got to change my codes n look for other approach

as pointed by both of u rightly
"Also, normally SQL queries do not guarantee the order of records unless the order by clause is used. So, without order by, the same query executed twice could, theoretically, return the same records in two totally different orders."

there is no guarantee that order of records would be same ...

so simply matching row wise ... would not generate desired result

ll get back with new set of codes
# 25  
Old 11-14-2007
Dana, I don't think your problem is in your input files - your problem is in your approach. You should *analyze* your requirements, make a plan how to implement them and *only then* write a program. The real knowledge you need to acquire is not "do i lay a brick here or there?" but "how does the house i want to build look like?".

Lets start over: you tell us, what you want to achieve and which data you have got. Then we help you develop a plan to derive the data you want from the data you have. Finally - but only after this step - we implement the plan into real existing software.

Sorry for becoming a little theoretical here, but you are having a very common problem among system administrators here: just because a program (yes, a script is a program like every other) might be short doesn't mean the way software engineers (real software engineers, not the itsy-bitsy mouse-pushers with their 5D - 6GL - graphical - object- blabla - tools) organize their work:

understand your goals (the goals of your customer)
organize what you have got to work with
define your requirements
make a plan to get from where you are to where you want to be
only then put this plan to work by writing the software

If you read the whole thread from the beginning it is like you ask how to change the tires of your car. It turns out, though, that your problem is not a tire, but your car doesn't work any more for reasons unknown and you just *think* that might have something to do with the tire needing to be changed. So you don't need to know hoe to change the tire but you need to find out the reason why your car won't go anymore - maybe its the tire, but maybe its something completely different. Lets get back to this step otherwise you might end up with a car with four brand new tires which still won't go because the gearbox is broken.

bakunin
# 26  
Old 11-14-2007
What a thread !
Interesting read and as bakunin has suggested it isn't the tire.
My impression from reading the thread is that Dana's kinda asking for a "dynamic" comparrison (if there is such a thing).
Especially when Dana mentions:
Quote:
the files file1 and file2 won't necessarily have the same number of rows .
But I still consider myself a novice so I'll end my rant here.

Cheers,
Cameron D)
# 27  
Old 11-14-2007
Quote:
try this,

Code:
perl -e ' open(FILE, "<", "f1"); while(<FILE>) { $fileHash{$_} = $. ; } close(FILE); open(FILE, "<", "f2"); while(<FILE>) { print $_ if ( $fileHash{$_} != $. ); } close(FILE); '

did you try the solution I had posted ?
# 28  
Old 11-14-2007
Quote:
just because a program (yes, a script is a program like every other) might be short doesn't mean the way software engineers (real software engineers, not the itsy-bitsy mouse-pushers with their 5D - 6GL - graphical - object- blabla - tools) organize their work:
bakunin -
just asking this question out of curiosity though this would not add any value to thread ?

So, what is the difference that you were trying to express between the software engineers and the real software engineers ?

I didn't understand when you said about the itsy-bitsy thing

Again - this question is only out of curiosity.
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #918
Difficulty: Medium
Unix time is a single signed number which increments every millisecond.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparison of files

I have the requirement I have two files cat fileA something anythg nothing everythg cat fileB everythg anythg Now i shld use fileB and compare every line at fileA and get the output as something nothing (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

2. Shell Programming and Scripting

UNIX file comparison

I have two files which has component name and version number separated by a space cat file1 com.acc.invm:FNS_PROD 94.0.5 com.acc.invm:FNS_TEST_DCCC_Mangment 94.1.6 com.acc.invm:FNS_APIPlat_BDMap 100.0.9 com.acc.invm:SendEmail 29.6.113 com.acc.invm:SendSms 12.23.65 cat file2 ... (8 Replies)
Discussion started by: rakeshtomar82
8 Replies

3. Shell Programming and Scripting

Need help regarding comparison between two files through UNIX script

Hi All , I am aware of unix command ,but not comforable in putting together in script level.I came to situation where I need to compare between two .txt files fieldwise and need a mismatch report. As I am new to unix script arena ,if anyone can help in the below scenario that will be really... (9 Replies)
Discussion started by: STCET22
9 Replies

4. Shell Programming and Scripting

Comparison between two files through UNIX script

Hi All , As I am new to unix scripting ,I need a help regarding unix scripting .I have two .txt files .One is source file and another is target file.I need a script through which I can compare those two files.I need a automated comparison report in a directory after comparing between source &... (2 Replies)
Discussion started by: STCET22
2 Replies

5. Shell Programming and Scripting

File comparison in UNIX columnwise

Hi all, I want to compare two files with same number of rows and columns with records in same order. Just want to highlight the differences in the column values if any. file A 1,kolkata,19,ab 2,delhi,89,cd 3,bangalore,56,ef file2: 1,kolkata,21,ab 2,mumbai,89,gh 3,bangalore,11,kl... (9 Replies)
Discussion started by: prabhat.diwaker
9 Replies

6. Shell Programming and Scripting

Comparison of two files

Hi all I have two files which I have to compare that whetehr there is soemthing common or not body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: "Liberation Sans"; font-size: x-small; } body, div, table, thead, tbody, tfoot,... (2 Replies)
Discussion started by: manigrover
2 Replies

7. Shell Programming and Scripting

comparison of 2 files using unix or awk

Hello, I have 2 files and I want them to be compared in a specific fashion file1: A_1200_1250 A_1251_1300 B_1301_1350 B_1351_1400 B_1401_1450 C_1451_1500 and so on... file2: 1210 1305 1260 1295 1400 1500 1450 1495 Now The script should look for "1200" from A_1200_1250 of... (8 Replies)
Discussion started by: Diya123
8 Replies

8. Shell Programming and Scripting

Comparison of two files (sh)

Hi, I have a problem with comparison of two files file1 20100101 20090101 20080101 20071001 20121229 file2 19990112 12 456 7 20011131 19 20100101 2 567 1 987 17890709 123 555 and, sh script needs to compare of these two files and give out to me result: 20100101 2 567 1 987 it... (5 Replies)
Discussion started by: shizik
5 Replies

9. Shell Programming and Scripting

comparison of 2 files

Kindly help on follows. I have 2 files. One file contains only one column of mobile numbers. And total records in a file 12 million. Second file contains 2 columns mobile numbers and balance. and total records 30 million. I want to find out balance of each data in file 1 corresponding to file 2.... (2 Replies)
Discussion started by: kamal_418
2 Replies

10. UNIX for Dummies Questions & Answers

Unix comparison

I am very new to Unix. What are the similiarities and differences between ScoUnix and AIX5 if any? Where might i find the information? Which is better? (1 Reply)
Discussion started by: NewGuy100
1 Replies

Featured Tech Videos