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
Need Help Comparing two Files awknerd Shell Programming and Scripting 4 09-03-2008 01:24 AM
Comparing two files superstar003 Shell Programming and Scripting 2 05-08-2008 05:36 AM
Comparing two txt files - pls help jisha Shell Programming and Scripting 5 01-23-2008 04:14 AM
Comparing two files.. padarthy Shell Programming and Scripting 1 08-29-2007 09:01 AM
comparing shadow files with real files terrym UNIX for Advanced & Expert Users 4 02-09-2007 02:38 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 09-16-2008
kanu_kanu kanu_kanu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 15
Comparing two files using awk

Hi,

I have 2 text files n1 and n2.

cat n1 :
--------
1234567890
4444444444

cat n2 :
---------
1234567890
4444444444
7777777777
8888888888

they are some sample records. File n1 contains some lookup records, whereas file n2 contains some transaction records. I need to get the transaction records from file n2 , which are not there in lookup file n1. For eg., from the above files I should get :

7777777777
8888888888

Is there any way using AWK arrays? grep will run for hours since the records are millions.

Thanks in advance

kanu_kanu
  #2 (permalink)  
Old 09-16-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813
This is based on your example:

Code:
awk 'FILENAME=="file1" {arr[$0]++}
       FILENAME=="file2"{ if($0 in arr) {continue}
                         else {print $0}}'  file1 file2

  #3 (permalink)  
Old 09-16-2008
kanu_kanu kanu_kanu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 15
Thanks... working
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 06:24 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