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.
This prints only matching entries from file a in fileb i want all entries from filea if it exists or not in fileb
nawk -F"|" 'NR==FNR{a[$1];next} $1 in a{print $1} filea fileb
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.
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.
BEGIN {FS=","}
for (i=0;i< ARGC;i++)
{ARGV=="fileb"{b[$1]++}
ARGV=="filec"{c[$1]++}
ARGV=="filed"{d[$1]++}
ARGV=="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:
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
Given the 'Search' capability of the forums and 'hints' given in the previous posts.......
nawk -f 3fileLookup.awk fileb filec filed filea
3fileLookup.awk:
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":""
}