The UNIX and Linux Forums  


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
file size comparision local file and remote file dba.admin2008 Shell Programming and Scripting 4 11-13-2008 05:57 PM
Problem with reading file line-by-line, and outputting to a new file Darkness Fish Shell Programming and Scripting 4 07-18-2008 07:54 AM
while - comparision sharif Shell Programming and Scripting 2 11-01-2007 05:58 AM
Unix File Comparision coolguy01 Shell Programming and Scripting 5 08-29-2006 03:35 AM
File Comparision by using Shell Script nvkuriseti Shell Programming and Scripting 3 08-31-2005 04:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-20-2008
aaysa123 aaysa123 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 19
file comparision by line

i have two files and i want to compare these two
it shoud print those lines which are not in 2nd file
a.txt
1236,AB,0
2345,CD,1
5679,EF,1
9123,AA,1
9223,AA,0

b.txt
1234,AB,0
2345,CD,1
5678,EF,1
9123,AA,0
o/p
1236,AB,0
5679,EF,1
9123,AA,1
9223,AA,0
  #2 (permalink)  
Old 11-20-2008
mailme0712 mailme0712 is offline
Registered User
  
 

Join Date: Sep 2008
Location: Chennai,India
Posts: 13
Hi,

use the following command

comm -23 <(sort file1) <(sort file2)




Thanks,

Thangaraju
  #3 (permalink)  
Old 11-20-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,289
All line of file1 are also in file2; maybe you meant it vice versa:
Code:
grep -vf file1 file2
B,0
5678,EF,1
9123,AA,0
o/p
Else just switch the position of the files in the grep command.
  #4 (permalink)  
Old 11-20-2008
yongitz yongitz is offline
Registered User
  
 

Join Date: Apr 2008
Location: Philippines
Posts: 68
I hope it's not homework. A simple grep command will do the task..
Code:
grep -vf b.txt a.txt

::EDIT:: oopppss! same answer with d above post
  #5 (permalink)  
Old 11-20-2008
aaysa123 aaysa123 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 19
thanks for reply but can we do it using nawk as grep -v is not running
  #6 (permalink)  
Old 11-20-2008
yongitz yongitz is offline
Registered User
  
 

Join Date: Apr 2008
Location: Philippines
Posts: 68
If you can't use grep then try the comm command given above with a little modification
Code:
comm -23 a.txt b.txt
  #7 (permalink)  
Old 11-21-2008
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
Cool awk command to comapre two files

if u have two files
first file and second file

awk command will be

awk 'BEGIN {while (getline <"first file") {arr[$0]++}}
{ if (!($0 in arr) {print }}' second file
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 08:29 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