LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-18-2014, 03:16 AM   #1
apoorvajoshi
LQ Newbie
 
Registered: Sep 2014
Posts: 2

Rep: Reputation: Disabled
Compare two CSV files


Hi, I have to compare two .csv files and get the output in other file in the given format.

First column in provided files would be unique.

If a new line is added I want A followed by "," and then followed by entire new row. If a line is modified I want C followed by "," and then followed by entire modified row. If a line is deleted I want D followed by "," and then followed by entire deleted row.

File 1

aa, bb, cc, dd, ee
bb, ww, ee, tt, yy
cc, vv, vv, vv, vv

File 2
bb, ww, ee, tt, y1
cc, vv, vv, vv, vv
nn, bb, nn, cc, bb

So output be like

D, aa, bb, cc, dd, ee
C, bb, ww, ee, tt, y1
A, nn, bb, nn, cc, bb

Last edited by apoorvajoshi; 09-18-2014 at 03:18 AM.
 
Old 09-18-2014, 03:26 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,286

Rep: Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165
So, what did you come up with ?.
Why didn't it work ?.
 
Old 09-18-2014, 03:31 AM   #3
apoorvajoshi
LQ Newbie
 
Registered: Sep 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Actually, I was diff command but it gives very raw data. I thought it would be really helpful to update the data in DB when the output will be in this format.

I got this over internet

diff -W999 --side-by-side OLD NEW |
sed '/^[^\t]*\t\s*|\t\(.*\)/{s//\1 U/;b};/^\([^\t]*\)\t*\s*<$/{s//\1 D/;b};/^.*>\t\(.*\)/{s//\1 N/;b};d'

But it is not working fine for me.

---------- Post added 09-18-14 at 01:02 PM ----------

Actually, I was diff command but it gives very raw data. I thought it would be really helpful to update the data in DB when the output will be in this format.

I got this over internet

diff -W999 --side-by-side OLD NEW |
sed '/^[^\t]*\t\s*|\t\(.*\)/{s//\1 U/;b};/^\([^\t]*\)\t*\s*<$/{s//\1 D/;b};/^.*>\t\(.*\)/{s//\1 N/;b};d'

But it is not working fine for me.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using SED to compare two csv files and update accordingly smokeyj Linux - Newbie 2 06-26-2014 12:27 PM
[SOLVED] Bash scripting problem: CSV list of filenames and actual files compare; Issue with plus symbol gn000we Linux - General 2 08-05-2013 07:57 PM
[SOLVED] How to compare a list of files in two directories: compare content and print size Batistuta_g_2000 Linux - Newbie 9 03-24-2013 08:05 AM
How to read CSV data and compare the column values and then write them in new file VijayaRaghavanLakshman Linux - Newbie 9 01-26-2012 10:02 PM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 10:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration