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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can I know find syntax to find given date files bache_gowda Shell Programming and Scripting 3 03-26-2008 02:37 AM
Find duplicates from multuple files with 2 diff types of files ricky007 Shell Programming and Scripting 2 03-04-2008 09:46 AM
Little bit weired : Find files in UNIX w/o using find or where command jatin.jain Shell Programming and Scripting 10 09-19-2007 03:47 AM
how to find duplicate files with find ? umen Shell Programming and Scripting 8 09-04-2006 12:01 AM
Find files older than 20 days & not use find halo98 Shell Programming and Scripting 2 05-18-2006 11:19 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-30-2008
Registered User
 

Join Date: Apr 2008
Posts: 4
Find the intersection between two files

How can find the intersection between files
for Example:
file1
entry1
entry2
entry3
entry33


file2
entry2
entry4
entry5
.
.
.
.
the output should be
entry2

Thanks in advanced
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-30-2008
Registered User
 

Join Date: Oct 2007
Posts: 7
Hi,

You can get the expected output using for loop as follows.

for i in `cat file1 | awk {'print $1'}`
do
grep ${i} file2
done


Thanks,
Aketi...
Reply With Quote
  #3 (permalink)  
Old 04-30-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,615
With awk:

Code:
awk 'NR==FNR{a[$0]=$0;next}a[$0]' file1 file2
Regards
Reply With Quote
  #4 (permalink)  
Old 04-30-2008
Registered User
 

Join Date: Apr 2008
Posts: 4
Quote:
Originally Posted by Mr.Aketi View Post
Hi,

You can get the expected output using for loop as follows.

for i in `cat file1 | awk {'print $1'}`
do
grep ${i} file2
done


Thanks,
Aketi...

its give me nothing
Reply With Quote
  #5 (permalink)  
Old 04-30-2008
Registered User
 

Join Date: Apr 2008
Posts: 4
Quote:
Originally Posted by Franklin52 View Post
With awk:

Code:
awk 'NR==FNR{a[$0]=$0;next}a[$0]' file1 file2
Regards
its give me this error

awk: syntax error near line 1
awk: bailing out near line 1

regards,
Ismail
Reply With Quote
  #6 (permalink)  
Old 04-30-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,615
Use nawk or /usr/xpg4/bin/awk on Solaris.
Reply With Quote
  #7 (permalink)  
Old 04-30-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 436
Code:
grep -f file1 file2
Reply With Quote
Google UNIX.COM
Reply

Tags
solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0