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
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 9 06-08-2009 06:11 AM
insert file2 after line containing patternX in file1 repudi8or Shell Programming and Scripting 5 04-18-2008 01:35 PM
echo "ABC" > file1.txt file2.txt file3.txt ganapati UNIX for Dummies Questions & Answers 4 01-30-2008 12:36 AM
Awk Compare f1,f2,f3 of File1 with f1 of File2 RacerX Shell Programming and Scripting 6 11-09-2007 01:34 AM
delete lines from file2 beginning w/file1 michieka Shell Programming and Scripting 13 06-24-2003 01:42 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 02-11-2008
myguess21 myguess21 is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 15
match value from file1 in file2

Hi, i've two files (file1, file2) i want to take value (in column1) and search in file2 if the they match print the value from file2.

this is what i have so far.

awk 'FILENAME=="file1"{ arr[$1]=$1 }
FILENAME=="file2"
{print $0}
' file1 file2
  #2 (permalink)  
Old 02-11-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
try:
Code:
awk 'FILENAME=="file1"{ arr[$1]=$1 }
      FILENAME=="file2" {if(arr($1] ) {print $0} }
' file1 file2
  #3 (permalink)  
Old 02-21-2008
myguess21 myguess21 is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 15
Hi Jim, thanks this is working.

what should i do if i want to compare file2 (col1) not in file1 (Anywhere in file). then print the line from FILE2.


Quote:
Originally Posted by jim mcnamara View Post
try:
Code:
awk 'FILENAME=="file1"{ arr[$1]=$1 }
      FILENAME=="file2" {if(arr($1] ) {print $0} }
' file1 file2
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 12:09 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