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
concatenate files sorted by date docaia Shell Programming and Scripting 2 08-16-2008 02:23 AM
executing code on files in the sorted order -help! epi8 Shell Programming and Scripting 1 05-20-2008 03:30 AM
Compare two files amir07 Shell Programming and Scripting 6 03-26-2008 11:23 AM
Compare files kharen11 UNIX for Advanced & Expert Users 25 03-14-2007 05:35 AM
help! need to compare files danielsf Shell Programming and Scripting 6 07-09-2003 05:09 PM

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 01-21-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Lightbulb Compare 2 sorted files

Hi all,

please give me the commands using which i can compare 2 sorted files and get the difference in third file, indiating where the difference is from either file1 or file2.

as:

File1 (Original file)

GARRY
JOHN
JULIE
SAM

---------------
File2

DEV
GARRY
JOHN
JOHNIEE
JULIE
RAMEE
SAM
SAMYEE
-------------------
OUTPUT in file3 should have :

DEV
JOHNIEE
RAMEE
SAMYEE


Using awk and diff/cmp commands.
  #2 (permalink)  
Old 01-21-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 555
Try this:
Code:
comm -13 file1 file2
Code:
diff file1 file2 | awk '/^>/{print $2 }'
  #3 (permalink)  
Old 01-22-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Exclamation

Quote:
Originally Posted by dennis.jacob View Post
Try this:
Code:
comm -13 file1 file2
Code:
diff file1 file2 | awk '/^>/{print $2 }'

Could you please tell me why -13 is being used in comm command ?
  #4 (permalink)  
Old 01-22-2008
ranjithpr ranjithpr is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 157
Try this one

grep -x -v -f F1 F2
  #5 (permalink)  
Old 01-22-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Thumbs up

Quote:
Originally Posted by ranjithpr View Post
grep -x -v -f F1 F2
Hey,

thanks man, hope this'll work fine.



Varun.
  #6 (permalink)  
Old 01-23-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 555
Quote:
Originally Posted by varungupta View Post
Could you please tell me why -13 is being used in comm command ?


-1 suppress lines unique to left file

-2 suppress lines unique to right file

-3 suppress lines that appear in both files
  #7 (permalink)  
Old 01-25-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Lightbulb

Quote:
Originally Posted by ranjithpr View Post
grep -x -v -f F1 F2
Hey,

I have attached 2 files in this mail, please find those, in which i am doing comparisions.
Contents of EAIDVBR1.txt are standard and Contents of EAIDQBR1.txt are mixed.
I want list of all strings from EAIDQBR1.txt that are not there in EAIDVBR1.

Please have a look and let me know. As i have tries "grep -x -v -f F1 F2" command on these files and its not working effectively.

Let me know asap.
Thanks
Varun
Attached Files
File Type: txt EAIDQBR1.txt (6.1 KB, 13 views)
File Type: txt EAIDVBR1.txt (4.6 KB, 9 views)
Sponsored Links
Closed Thread

Bookmarks

Tags
unix commands

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 12:15 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