The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Comparison Unix and Windows file sysytem localp UNIX for Dummies Questions & Answers 1 04-11-2008 04:02 AM
Comparison of two files in awk jerome Sukumar Shell Programming and Scripting 12 07-26-2006 08:16 AM
String Comparison between two files using awk rudoraj Shell Programming and Scripting 7 07-25-2006 11:04 AM
Unix comparison NewGuy100 UNIX for Dummies Questions & Answers 1 12-14-2005 04:42 PM
Unix Programming Book Comparison theicarusagenda High Level Programming 6 03-04-2005 10:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 11-12-2007
Dana Evans Dana Evans is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 16
Comparison of 2 files in UNIX

Hi, There are two files in UNIX system with some lines are exactly the same, some lines are not.
I want to compare these two files.The 2 files (both the files have data in Column format )should be compared row wise and any difference in data for a particular row should lead to storage of data of second file in another new third file.
i.e here we are assuming second file( file 2 ) to be updated version of first file (file 1) and any difference in row wise matching would lead to storage of the updated /modified data in another third file .


Please help me ASAP
  #2 (permalink)  
Old 11-12-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
check if diff can solve your problem
  #3 (permalink)  
Old 11-12-2007
Dana Evans Dana Evans is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 16
Question

hi yogesh diff is NOT solving the problem ( i have tried that)..
bcoz the output apart from giving the difference in file contents is also displaying line numbers and other special kind of instructions ...

we got to pick up only the modified data from this third file .. so diff doesn't work out here properly
for eg below is one such display

1c1,2
< 1|2|2|2|4|3
---
> 1|2|3|2|3|4
>

Thank you

do let us know in case of any other options
  #4 (permalink)  
Old 11-12-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
So then pipe the diff output through a filter which just selects the changes you interested in, say by looking for lines either begining with < or >.
  #5 (permalink)  
Old 11-12-2007
Dana Evans Dana Evans is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 16
Unhappy

Porter here NOT all lines begin in same way/with same special characters

even i tried following the same stuff ( as suggested by u ) long time back

diff file1 file2 > diff_file.txt
cut -d"|" -f1 diff_file.txt|egrep -v ",|-|>|<" > final.txt

field 1( f1) was the desired field which was to be picked up from the diff_file.txt file .. but again problem is that the diff_file.txt contained the line numbers in some places Also
(note: diff_file.txt has huge number of rows of data) ,so these unwanted line numbers which lie in same column as the field 1 data also gets picked up with the field1 data

eg line numbers like 4d3,5a5 etc
Note :file 1 n file 2 contains numbers as data
so i want final.txt file to have pure numbers only
  #6 (permalink)  
Old 11-12-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Perhaps grep might help.

Code:
grep -vf file1 file2 > file3
Eg.

Code:
[/tmp]$ cat file1
1 2
2 3
3 4
4 5
5 6
[/tmp]$ cat file2
1 2
2 4
3 6
4 5
5 6
[/tmp]$ grep -vf file1 file2 > file3
[/tmp]$ cat file3
2 4
3 6
[/tmp]$
  #7 (permalink)  
Old 11-12-2007
Dana Evans Dana Evans is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 16
Unhappy

Hey Vino thanks a lottt !!!!! ..but again ur suggestion is applicable only when both the files have certain contents which are unique to that particular file and NOT found in other one ...

for eg
two files file3 having contents
bat
mat
rat


and file4 having contents
bat
rat
hat


in such case grep -vf file3 file4
would display only "hat" and not rat because rat is present there is file 3

but our criteria is that
rat as well as hat should be displayed as we are matching the column contents row wise ONLY.. so here the values at second and third place of file 4 differ from those of file 3 so accordingly i want rat and hat to be displayed
any idea
Sponsored Links
Closed Thread

Bookmarks

Tags
diff, grep, perl, perl shift, shift, shift perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0