Difference between two huge .csv files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Difference between two huge .csv files
# 1  
Old 10-07-2012
Difference between two huge .csv files

Hi all,

I need help on getting difference between 2 .csv files.
I have 2 large . csv files which has equal number of columns. I nned to compare them and get output in new file which will have difference olny.

E.g.
File1.csv
Code:
Name, Date, age,number 
Sakshi, 16-12-2011, 22, 56
Akash, 14-12-2011, 23, 76

File2.csv
Code:
Name,Date,age,number
Sakshi, 14-12-2011,22,56
Akash,18-12-2011,23,76

then output should be like
Code:
16-12-2011                      14-12-2011
14-12-2011                       18-12-2011

It's just an example. What I am trying to say is I should get only the values of columns where we have the difference. Not the whole line.
Assuming File will be in sorted order.
There can be m number of columns but for sure in both the files, we will get same columns. If values are different then those values should be given in output.
It can also work if we can get difference in comma separated file like
wherver values matches between 2 files we get blank
,16-12-2011,,
Hope I am able to explain the issue.

Last edited by Franklin52; 10-08-2012 at 04:07 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 10-07-2012
Code:
awk -F, 'FNR==NR{a[$1]=$2;next}{if(a[$1]!=$2){print a[$1],$2}}' file1 file2

# 3  
Old 10-07-2012
I think I am not able to explain issue properly.

In the example given, there is a difference at 2nd column only. But there can be difference in some other columns value as well. This command is giving result for difference at 2nd place only.
Can you give me the command so that I can get result in comma separated format only. By this I will get to know wherever values are not matching in our files.
It's not neccessary to get values from both the file. Let say there is difference at 3rd column and 7th column so my result should be like
,,17-12-2011,,,,10,,,,,,,,,

Please help
# 4  
Old 10-07-2012
try with this..

Code:
paste file1 file2 | awk -F "[,\t]" '{for(i=1;i<=(NF/2);i++){if($i != $(NF/2+i)){printf $i}else{printf ","}}}{print ""}'

# 5  
Old 10-08-2012
Thanks for the help.Smilie

But still have one issue.

If i have difference in 2 consecutive columns, it's not showing any separation between them.
E.g
File1
Rahul, 1203,113,11

File2
Malik, 121,113,11

Output coming as Rahul1203,,

Expected Output: Rahul,1203,,
# 6  
Old 10-08-2012
Quote:
Originally Posted by Dimple

If i have difference in 2 consecutive columns, it's not showing any separation between t
What about FS for all the values. So you can easily distinguish between them...

Code:
paste file1 file2 | awk -F "[,\t]" '{for(i=1;i<=(NF/2);i++){if($i != $(NF/2+i)){
if(s){s=s";"$i}else{s=$i}}else{if(s){s=s";,"}else{s=","}}}}{ print s;s=""}'

# 7  
Old 10-09-2012
Bug

Thanks for your help Smilie

It's working exactly what I want.

If possible Can you please explain the code.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 csv files in ksh and o/p the difference in a new csv file

(say) I have 2 csv files - file1.csv & file2.csv as mentioned below: file1.csv ID,version,cost 1000,1,30 2000,2,40 3000,3,50 4000,4,60 file2.csv ID,version,cost 1000,1,30 2000,2,45 3000,4,55 6000,5,70 The... (7 Replies)
Discussion started by: Naresh101
7 Replies

2. Shell Programming and Scripting

Comparing 2 CSV files and sending the difference to a new csv file

(say) I have 2 csv files - file1.csv & file2.csv as mentioned below: file1.csv ID,version,cost 1000,1,30 2000,2,40 3000,3,50 4000,4,60 file2.csv ID,version,cost 1000,1,30 2000,2,45 3000,4,55 6000,5,70 ... (1 Reply)
Discussion started by: Naresh101
1 Replies

3. Shell Programming and Scripting

Compare two CSV files and put the difference in third file with line no,field no and diff value.

I am having two csv files i need to compare these files and the output file should have the information of the differences at the field level. For Example, File 1: A,B,C,D,E,F 1,2,3,4,5,6 File 2: A,C,B,D,E,F 1,2,4,5,5,6 out put file: (12 Replies)
Discussion started by: karingulanagara
12 Replies

4. Shell Programming and Scripting

Comparing 2 difference csv files

Hello, I have about 10 csv files which range from csv1 - csv10. Each csv file has same type/set of tabs and we have around 5-6 tabs for each of the csv file which have slightly different content(data). A sample of CSV1 is shown below: Joins: Data related to Joins, it can be any number of... (2 Replies)
Discussion started by: bobby1015
2 Replies

5. Shell Programming and Scripting

Format & Compare two huge CSV files

I have two csv files having 90K records each & each row has around 50 columns.Lets say the file names are FILE1 and FILE2. I have to compare both the files and generate a new file that has rows from FILE2 if it differs. FILE1 ----- 2001,"John",25,19901130,21211.41,Unix Forum... (3 Replies)
Discussion started by: Sheel
3 Replies

6. Shell Programming and Scripting

Three Difference File Huge Data Comparison Problem.

I got three different file: Part of File 1 ARTPHDFGAA . . Part of File 2 ARTGHHYESA . . Part of File 3 ARTPOLYWEA . . (4 Replies)
Discussion started by: patrick87
4 Replies

7. Shell Programming and Scripting

Counting difference in two CSV files

Hi, I am new to awk and trying to count the difference between the first columns of two CSV files. -------- Sample input (header is:name, id1,id2): file1.csv name, id1,id2 sss,34,56 yyy,3,56 www,56,78 pppp,43,12 file2.csv name,id1,id2 sss,32,56 yyy,12,7 ttt,4,8 uuu,7,9 (0 Replies)
Discussion started by: sam40
0 Replies

8. Programming

Huge difference between _POSIX_OPEN_MAX and sysconf(_SC_OPEN_MAX).

On my Linux system there seems to be a massive difference between the value of _POSIX_OPEN_MAX and what sysconf(_SC_OPEN_MAX) returns and also what I'd expect from the table of examples of configuration limits from Advanced Programming In The UNIX Environment, 2nd Ed. _POSIX_OPEN_MAX: 16... (5 Replies)
Discussion started by: gencon
5 Replies

9. AIX

Huge difference in reported Disk usage between ls,df and du

IBM RS6000 F50 AIX 4.3.2 i am having trouble in calculating the actual size of a set of directories and reconciling the results with the actual Hard Disk space used I have 33GB disk which is showing 7.8GB used, a byte count of the files in the directory/sub-dirs i`m interested in is 48GB,... (4 Replies)
Discussion started by: cooperuf
4 Replies

10. UNIX for Dummies Questions & Answers

Difference between two huge files

Hi, As per my requirement, I need to take difference between two big files(around 6.5 GB) and get the difference to a output file without any line numbers or '<' or '>' in front of each new line. As DIFF command wont work for big files, i tried to use BDIFF instead. I am getting incorrect... (13 Replies)
Discussion started by: pyaranoid
13 Replies
Login or Register to Ask a Question