Multiple file lookup using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple file lookup using awk
# 8  
Old 05-27-2009
Quote:
Originally Posted by vgersh99
This so called 'effort' looks suspiciously similar to a previously posted and deleted suggestion with some minor cosmetic changes.

This is hard effort of person who is familar with 2 files lookup and not with multiple files and with argv


Appreciate help
# 9  
Old 05-27-2009
Given the 'Search' capability of the forums and 'hints' given in the previous posts.......

nawk -f 3fileLookup.awk fileb filec filed filea

3fileLookup.awk:
Code:
BEGIN {
  FS=OFS=","
}
FILENAME == ARGV[1] {
   b[$1]++
   next
}
FILENAME == ARGV[2] {
   c[$1]++
   next
}
FILENAME == ARGV[3] {
   d[$1]++
   next
}
{
  print $1, ($1 in b && $1 in c)?"Y":"", ($1 in d)?"Y":""
}

# 10  
Old 05-27-2009
Quote:
Originally Posted by vgersh99
Given the 'Search' capability of the forums and 'hints' given in the previous posts.......

nawk -f 3fileLookup.awk fileb filec filed filea

3fileLookup.awk:
Code:
BEGIN {
  FS=OFS=","
}
FILENAME == ARGV[1] {
   b[$1]++
   next
}
FILENAME == ARGV[2] {
   c[$1]++
   next
}
FILENAME == ARGV[3] {
   d[$1]++
   next
}
{
  print $1, ($1 in b && $1 in c)?"Y":"", ($1 in d)?"Y":""
}


Here is what i coded with 2 file lookup at a time, this works but creates unneccessary intermediate files

Code:
nawk -F"|" 'NR==FNR{a[$1];next} {if($1 in a) print $1,"Y"; else print $1 OFS}'  OFS="|"  fileb filea > out 
nawk -F"|" 'NR==FNR{a[$1];next} {if($1 in a) print $0,"Y"; else print $0 OFS}'  OFS="|"   filec out > out1

nawk -F"|" 'NR==FNR{a[$1];next} {if($1 in a) print $0,"Y"; else print $0 OFS}'  OFS="|"  filed out1 > out2

nawk -F"|" '{if ($2 =="Y" && $3 == "Y") print $1,"Y",$4 ;else print $1 OFS OFS $4}' OFS="|"  outing2

Thanks Vrgesh99
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk conditional operators- lookup value in 2nd file

I use conditional operators alot in AWK to print rows from large text files based on values in a certain column. For example: awk -F '\t' '{ if ($1 == "A" || $1 == "C" ) print $0}' OFS="\t" file1.txt > file2.txt In this case every row is printed from file1 to file2 for which the column 1... (5 Replies)
Discussion started by: Geneanalyst
5 Replies

2. Shell Programming and Scripting

awk to lookup stored variable in file and print matching line

The bash bash below extracts the oldest folder from a directory and stores it in filename That result will match a line in bold in input. In the matching line there is an_xxx digit in italics that (once the leading zero is removed) will match a line in link. That is the lint to print in output.... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

awk to lookup value in one file in another range

I am trying to update the below awk, kindly provided by @RavinderSingh13, to update each line of file1 with either Low or No Low based on matching $2 of file1 to a range in $2 and $3 of file2. If the $2 value in file1 matches the range in file2 then that line is Low, otherwise it is No Low in the... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

awk to lookup section of file in a range of another file

In the below, I am trying to lookup $1 and $2 from file1, in a range search using $1 $2 $3 of file2. If the search key from file1 is found in file2, then the word low is printed in the last field of that line in the updated file1. Only the last section of file1 needs to be searched, but I am not... (6 Replies)
Discussion started by: cmccabe
6 Replies

5. Shell Programming and Scripting

awk to print field from lookup file in output

The below awk uses $3 and $4 in search as the min and max, then takes each $2 value in lookup and compares it. If the value in lookupfalls within the range in searchthen it prints the entire line in lookup/ICODE]. What I can't seem to figure out is how to print the matching $5 from search on that... (4 Replies)
Discussion started by: cmccabe
4 Replies

6. Shell Programming and Scripting

Combined sed+awk for lookup csv file

have written a combined sed+awk to perform a lookup operation which works but looking to enhance it. looking to match a record using any of the comma separated values + return selected fields from the record - including the field header. so: cat foo make,model,engine,trim,value... (6 Replies)
Discussion started by: jack.bauer
6 Replies

7. UNIX for Dummies Questions & Answers

Help with AWK - Compare a field in a file to lookup file and substitute if only a match

I have the below 2 files: 1) Third field from file1.txt should be compared to the first field of lookup.txt. 2) If match found then third field, file1.txt should be substituted with the second field from lookup.txt. 3)Else just print the line from file1.txt. File1.txt:... (4 Replies)
Discussion started by: venalla_shine
4 Replies

8. UNIX for Dummies Questions & Answers

Multiple Column print after lookup using NR==FNR (awk)

foo.txt FAMID IID AFF SEX Group AgeCat Dis1 Dis2 Dis3 Dis4 Dis5 Dis6 Dis6 AMD0001 Mayo_49542 1 2 AMD 8 1 1 1 1 1 1 1 AMD0002 Mayo_49606 1 1 AMD 3 1 1 1 1 ... (7 Replies)
Discussion started by: genehunter
7 Replies

9. UNIX for Advanced & Expert Users

Clueless about how to lookup and reverse lookup IP addresses under a file!!.pls help

Write a quick shell snippet to find all of the IPV4 IP addresses in any and all of the files under /var/lib/output/*, ignoring whatever else may be in those files. Perform a reverse lookup on each, and format the output neatly, like "IP=192.168.0.1, ... (0 Replies)
Discussion started by: choco4202002
0 Replies

10. Shell Programming and Scripting

file Lookup using awk

Hi All, I have two files file1 and file2(lookup file).I need to map more than one keyfields of file1 with file2.how can we achieve it using awk. file1(max 2.2 million records) -------------------------- 680720|680721|077 680720|680721|978 680721|680722|090 file2(no idea about the... (1 Reply)
Discussion started by: jerome Sukumar
1 Replies
Login or Register to Ask a Question