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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
compare columns from seven files and print the output smriti_shridhar Shell Programming and Scripting 7 06-11-2008 12:22 AM
compare two files and print the last row into first cdfd123 Shell Programming and Scripting 1 04-27-2008 08:23 AM
awk to compare lines of two files and print output on screen chlfc Shell Programming and Scripting 3 03-24-2008 04:16 AM
compare 2 file and print difference in the third file URG PLS evvander Shell Programming and Scripting 3 09-24-2007 06:52 AM
compare two .dat files and if there is any difference pulled into a separate file kirankumar Shell Programming and Scripting 1 04-19-2006 02:13 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 Rate Thread Display Modes
  #1 (permalink)  
Old 10-05-2007
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
Smile to compare two files and to print the difference

suppose one file
P1168S
P2150L
P85L
Q597R
R1097C

Another file
P2150L
P85L
Q597R
R1097C
R1379C
R1587K

Then output shud be
R1379C
R1587K

thanks
  #2 (permalink)  
Old 10-05-2007
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Quote:
Originally Posted by cdfd123 View Post
suppose one file
P1168S
P2150L
P85L
Q597R
R1097C

Another file
P2150L
P85L
Q597R
R1097C
R1379C
R1587K

Then output shud be
R1379C
R1587K

thanks
Why not P1168S - it is not in "another file"
  #3 (permalink)  
Old 10-05-2007
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
use cmp file1 file2
or
diff file1 file2

what exactly are you looking for?

cheers,
Devaraj Takhellambam
  #4 (permalink)  
Old 10-06-2007
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
Quote:
Originally Posted by devtakh View Post
use cmp file1 file2
or
diff file1 file2

what exactly are you looking for?

cheers,
Devaraj Takhellambam
yah ....
u have a file1 and file2 then contents not found in file 2 shud be displayed
  #5 (permalink)  
Old 10-06-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 560
Use this...Please note that this will work for sorted files

Code:
comm -23 file1 file2
  #6 (permalink)  
Old 10-06-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Code:
awk 'BEGIN { while ( getline < "firstfile" ) { arr[$0]++ } } { if (!( $0 in arr ) ) { print } }' secondfile
Closed Thread

Bookmarks

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:21 AM.


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