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.

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 10-29-2008
amir07 amir07 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 37
Smile Need help in awk

I have the following two files. Please help me with awk script ,which will grab corresponding ip in file2 for each entry in file1. so the out put should like this:

Thanks,


10.1.1.1 abc00def
10.1.1.2 abc00dee
10.1.1.3 abc00deg
10.1.1.4 abc00deg
10.1.1.5 abc00der
10.1.1.6 abc00det
10.1.1.7 abc00dep
10.1.1.8 abc00deq
10.1.1.9 abc00dep

File1:

abc00def
abc00dee
abc00deg
abc00deg
abc00der
abc00det
abc00dep
abc00deq
abc00dep


File2:


10.1.1.1 abc00def
10.1.1.2 abc00dee
10.1.1.3 abc00deg
10.1.1.4 abc00deg
10.1.1.5 abc00der
10.1.1.6 abc00det
10.1.1.7 abc00dep
10.1.1.8 abc00deq
10.1.1.9 abc00dep
10.1.1.5 ber00tys
10.2.1.1 ver00mrt
10.1.1.9 yer00tys
10.2.1.5 zer00mrt
  #2 (permalink)  
Old 10-29-2008
mirusnet's Avatar
mirusnet mirusnet is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 146
for i in `cat a`; do grep $i b >>c; done
  #3 (permalink)  
Old 10-29-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,312
Or just:
Code:
grep -f file1 file2
  #4 (permalink)  
Old 10-30-2008
paresh n doshi paresh n doshi is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 38
when two files are sorted, use join command
join -t" " -j1 1 -j2 2 -o 1.1 2.2 filea fileb
  #5 (permalink)  
Old 10-31-2008
amir07 amir07 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 37
Thanks, this code :

for i in `cat a`; do grep $i b >>c; done
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 05:22 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