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
Clueless about how to lookup and reverse lookup IP addresses under a file!!.pls help choco4202002 UNIX for Advanced & Expert Users 0 08-26-2008 02:28 PM
Lookup file mohan705 Shell Programming and Scripting 4 08-05-2008 05:22 AM
Lookup on a file ukatru Shell Programming and Scripting 4 07-31-2008 02:25 AM
Lookup with a file pavan_test UNIX for Dummies Questions & Answers 5 07-21-2006 11:57 AM
file lookup gillbates UNIX for Dummies Questions & Answers 6 12-12-2003 02:04 PM

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 05-27-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
Multiple file lookup using awk

I want to lookup filea with fileb,filec and filed.
If entry in filea exist in fileb and filec mark Y and then if entry in filea exist in filed mark as Y.
Final output should have all the entries from filea.

Quote:
filea:
abc
def
ghi
jkl

fileb:
abc,tt
def,kk

filec:
abc,ii
ghi,nn
filed:
ghi,aa
jkl,mm

output:
filea,fileb&c,filed
abc,Y,
def,,
ghi,,Y
jkl,,Y
This prints only matching entries from file a in fileb i want all entries from filea if it exists or not in fileb


Code:
nawk -F"|" 'NR==FNR{a[$1];next} $1 in a{print $1} filea fileb

  #2 (permalink)  
Old 05-27-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,557
you can use while loops inside awk to get your file items into arrays.
  #3 (permalink)  
Old 05-27-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
Quote:
Originally Posted by ghostdog74 View Post
you can use while loops inside awk to get your file items into arrays.
Can you help me write the code
  #4 (permalink)  
Old 05-27-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,557
Quote:
Originally Posted by zenith View Post
Can you help me write the code
no. i will not because you are not putting in effort. always look up the manual or google if you don't know anything. this page. there is example of using while loop.
  #5 (permalink)  
Old 05-27-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
instead of while/getline combo for reading the files, you could could use a separate combos of FILENAME/ARGV and read the files into arrays. Checking the content of 'filea' in multiple read-in arrays should be straight-forward.
Search the forums for the terms mentioned above and it should give you enough as a starting hint.
Good luck.

Last edited by vgersh99; 05-27-2009 at 02:01 PM.. Reason: spelling
  #6 (permalink)  
Old 05-27-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
Quote:
Originally Posted by vgersh99 View Post
instead of while/getline combo for reading the files, you could could use a separate combos of FILENAME/ARGV and read the files into arrays. Checking the content of 'filea' in multiple read-in arrays should be straight-forward.
Search the forums for the terms mentioned above and it should give you enough as a starting hint.
Good luck.
All,

Here is my effort:

Code:
BEGIN {FS=","}
for (i=0;i< ARGC;i++)
{ARGV[i]=="fileb"{b[$1]++}
ARGV[i]=="filec"{c[$1]++}
ARGV[i]=="filed"{d[$1]++}
ARGV[i]=="filea"{if (($1 in b ) && ( $1 in c) && ($1 in d)) print $1,"Y" OFS
else
if (($1 in d) && !($1 in c) && !($1 in b)) print $1 OFS,"Y"
else
if (($1 in b) && ($1 in c) && !($1 in d)) print $1,"Y"OFS
else print $1 OFS OFS
}} OFS=","


command used : nawk -f awkfiles.awk fileb filec filed filea
Here is the error:

Quote:
nawk: syntax error at source line 2
context is
>>> for <<< (i=0;i< ARGC;i++)
nawk: bailing out at source line 2

Requirement:
Field 1 Filed2 Field 3
$1 of filea|"Y" if $1 of filea exist in fileb and filec| "Y" if $1 of filea exist in filed

Output needed:
abc,Y,
def,,
ghi,,Y
jkl,,Y


Your help is appreciate in fixing this.
  #7 (permalink)  
Old 05-27-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
This so called 'effort' looks suspiciously similar to a previously posted and deleted suggestion with some minor cosmetic changes.
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:58 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