File Compare and Create New File with Diff | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

File Compare and Create New File with Diff

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-14-2006
guiguy guiguy is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 12 June 2007, 6:56 PM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
File Compare and Create New File with Diff

I need to compare File A with File B and create FILE C with the difference record only. What I mean is File A has 3 records and File B has 4 records, so FILE C will only have 1 record (becuase that record is in FILE B and not in File A). Hope I am making sense. The data layout is that each data element is within double quotes and each field is seperated by a comma. In the example below after the second name there is a double quote and 3 commas, the first comma is the field seperator and the other 2 commas are for fields that there is no data, hence the commas.

File A

"00000000155","JOHN","SMITH",,,"1944-06-03",
"00000001166","SMITH","JOHN",,,"1947-24-01",
""00000002189","BOB","SMITH",,,"1947-03-04",

File B

"00000000155","JOHN","SMITH",,,"1944-06-03",
"00000001166","SMITH","JOHN",,,"1947-24-01",
""00000002189","BOB","SMITH",,,"1947-03-04",
""00000002263","SMITH","JOHN",,,"1948-02-24",


I am not sure what uniz command to use, I haev done some reading and it looks like I can use the diff command or maybe even teh awk command. If someone can provide assistance here , I would be greatly appreciate it.

Sincerely
Sponsored Links
    #2  
Old 12-14-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
AFK
 
Join Date: Dec 2004
Last Activity: 28 July 2014, 9:39 AM EDT
Location: UK
Posts: 2,351
Thanks: 0
Thanked 6 Times in 6 Posts
Hm, try using the comm command. Its does exactly what you want to do.
Sponsored Links
    #3  
Old 12-14-2006
guiguy guiguy is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 12 June 2007, 6:56 PM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
File Compare and Create New File with Diff

Thanks for your resposne, but I tried the comm command and it is not working, this si what I tried

comm -23 file1 file2

Any assistance would be greatly apprecaited.

Thanks
    #4  
Old 12-14-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
 
Join Date: Feb 2006
Last Activity: 2 February 2012, 9:30 AM EST
Location: Indianapolis, IN
Posts: 255
Thanks: 0
Thanked 2 Times in 2 Posts
Both files need to be sorted first for comm to work.
Sponsored Links
    #5  
Old 01-06-2007
guiguy guiguy is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 12 June 2007, 6:56 PM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
File Compare in Unix

I had posted this earlier about 3 weeks ago and had recieved a response and I did sort both the files and the comm command is still not working.

Can someone please assist me, I would really appreciate it.

Below is what I am trying to do
I need to compare File A with File B and create FILE C with the difference record only. What I mean is File A has records and File B has records, so FILE C will only have the records which are not in File A. Hope I am making sense. The data layout is that each data element is within double quotes and each field is seperated by a comma. In the example below after the second name there is a double quote and 3 commas, the first comma is the field seperator and the other 2 commas are for fields that there is no data, hence the commas

Below are the sample file layout

File A


"00004006676","JOHN","SMITH",,,"1944-06-03",
"00004200004","JOHN","SMITH",,,"1944-06-03",
"00004200075","JOHN","SMITH",,,"1944-06-03",
"00004200101","JOHN","SMITH",,,"1944-06-03",
"00004200155","JOHN","SMITH",,,"1944-06-03",
"00004200245","JOHN","SMITH",,,"1944-06-03",
"00004200318","JOHN","SMITH",,,"1944-06-03",
"00004201166","JOHN","SMITH",,,"1944-06-03",
"00004202042","JOHN","SMITH",,,"1944-06-03",
"00004202189","JOHN","SMITH",,,"1944-06-03",
"00004202234","JOHN","SMITH",,,"1944-06-03",
"00004202263","JOHN","SMITH",,,"1944-06-03",
"00004202298","JOHN","SMITH",,,"1944-06-03",
"00004202365","JOHN","SMITH",,,"1944-06-03",
"00004202373","JOHN","SMITH",,,"1944-06-03",
"00004202491","JOHN","SMITH",,,"1944-06-03",
"00004202640","JOHN","SMITH",,,"1944-06-03",
"00004202745","JOHN","SMITH",,,"1944-06-03",
"00004202994","JOHN","SMITH",,,"1944-06-03",
"00004203032","JOHN","SMITH",,,"1944-06-03",
"00004203044","JOHN","SMITH",,,"1944-06-03",
"00004203238","JOHN","SMITH",,,"1944-06-03",
"00004203539","JOHN","SMITH",,,"1944-06-03",
"00004203553","JOHN","SMITH",,,"1944-06-03",
"00004203655","JOHN","SMITH",,,"1944-06-03",
"00004203669","JOHN","SMITH",,,"1944-06-03",
"00004203722","JOHN","SMITH",,,"1944-06-03",
"00004203762","JOHN","SMITH",,,"1944-06-03",
"00004203860","JOHN","SMITH",,,"1944-06-03",
"00004203887","JOHN","SMITH",,,"1944-06-03",
"00004207046","JOHN","SMITH",,,"1944-06-03",

File B

"00004006676","JOHN","SMITH",,,"1944-06-03",
"00004200004","JOHN","SMITH",,,"1944-06-03",
"00004200075","JOHN","SMITH",,,"1944-06-03",
"00004200101","JOHN","SMITH",,,"1944-06-03",
"00004200125","JOHN","SMITH",,,"1944-06-03",
"00004200130","JOHN","SMITH",,,"1944-06-03",
"00004200155","JOHN","SMITH",,,"1944-06-03",
"00004200245","JOHN","SMITH",,,"1944-06-03",
"00004200318","JOHN","SMITH",,,"1944-06-03",
"00004201166","JOHN","SMITH",,,"1944-06-03",
"00004202042","JOHN","SMITH",,,"1944-06-03",
"00004202189","JOHN","SMITH",,,"1944-06-03",
"00004202234","JOHN","SMITH",,,"1944-06-03",
"00004202263","JOHN","SMITH",,,"1944-06-03",
"00004202298","JOHN","SMITH",,,"1944-06-03",
"00004202307","JOHN","SMITH",,,"1944-06-03",
"00004202365","JOHN","SMITH",,,"1944-06-03",
"00004202373","JOHN","SMITH",,,"1944-06-03",
"00004202491","JOHN","SMITH",,,"1944-06-03",
"00004202640","JOHN","SMITH",,,"1944-06-03",
"00004202745","JOHN","SMITH",,,"1944-06-03",
"00004202994","JOHN","SMITH",,,"1944-06-03",
"00004203032","JOHN","SMITH",,,"1944-06-03",
"00004203238","JOHN","SMITH",,,"1944-06-03",
"00004203539","JOHN","SMITH",,,"1944-06-03",
"00004203553","JOHN","SMITH",,,"1944-06-03",
"00004203655","JOHN","SMITH",,,"1944-06-03",
"00004203669","JOHN","SMITH",,,"1944-06-03",
"00004203722","JOHN","SMITH",,,"1944-06-03",
"00004203762","JOHN","SMITH",,,"1944-06-03",
"00004203860","JOHN","SMITH",,,"1944-06-03",
"00004203887","JOHN","SMITH",,,"1944-06-03",
"00004207046","JOHN","SMITH",,,"1944-06-03",

The final results in File C would be the following records since these records are in File B and not in File A

"00004200125","JOHN","SMITH",,,"1944-06-03",
"00004200130","JOHN","SMITH",,,"1944-06-03",
"00004202307","JOHN","SMITH",,,"1944-06-03",

Sincerely

Hadi Lalani

Last edited by vino; 01-06-2007 at 02:47 PM.. Reason: remove email address...
Sponsored Links
    #6  
Old 01-06-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 19 September 2014, 2:05 PM EDT
Location: Ashburn, Virginia
Posts: 9,925
Thanks: 60
Thanked 435 Times in 260 Posts
guiguy, I just closed a duplicate thread and I see that vino had to edit your post to remove your email address. Please read the rules:

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.

(10) Don't post your email address and ask for an email reply. The forums are for the benefit of all, so all Q&A should take place in the forums.

As for your question, I copied your data into files which I named file_A and file_B. Then I tried:
Code:
$ comm -13 file_A file_B
"00004200125","JOHN","SMITH",,,"1944-06-03",
"00004200130","JOHN","SMITH",,,"1944-06-03",
"00004202307","JOHN","SMITH",,,"1944-06-03",
$
$

The man page is clear that comm -13 is what you need. You were suppressing the wrong column. You tried:
comm -23
which was wrong. There are only two other ways to print a single column:
comm -13
comm -12

Why not try them before you give up?
Sponsored Links
    #7  
Old 02-28-2007
bishweshwar bishweshwar is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 4 April 2009, 9:46 AM EDT
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
how for files not sorted

Quote:
Originally Posted by Perderabo
guiguy, I just closed a duplicate thread and I see that vino had to edit your post to remove your email address. Please read the rules:

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.

(10) Don't post your email address and ask for an email reply. The forums are for the benefit of all, so all Q&A should take place in the forums.

As for your question, I copied your data into files which I named file_A and file_B. Then I tried:
Code:
$ comm -13 file_A file_B
"00004200125","JOHN","SMITH",,,"1944-06-03",
"00004200130","JOHN","SMITH",,,"1944-06-03",
"00004202307","JOHN","SMITH",,,"1944-06-03",
$
$

The man page is clear that comm -13 is what you need. You were suppressing the wrong column. You tried:
comm -23
which was wrong. There are only two other ways to print a single column:
comm -13
comm -12

Why not try them before you give up?

How to get the common columns in two files that are not sorted...?
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using Diff to Compare 2 files ladyAnne Shell Programming and Scripting 9 04-07-2010 09:40 AM
Compare file timestamp with current date. Diff must be 1 hour. taipan Shell Programming and Scripting 3 12-28-2009 02:40 AM
Compare two csv files by two colums and create third file combining data from them. agb2008 Shell Programming and Scripting 5 02-16-2009 10:26 AM
Compare two files and output diff to third file altamaha Shell Programming and Scripting 8 09-25-2008 10:42 AM
diff 2 files; output diff's to 3rd file blt123 Shell Programming and Scripting 2 05-28-2002 11:29 AM



All times are GMT -4. The time now is 02:15 PM.