How to make this code working?

Hi Gurus,

I wrote a simple code, but it doesn't work, can body help me to fix the issue.

awk -F',' 'BEGIN{n=0}{
NR == FNR {fname[$1];next}
{
if ($3==fname)
n=1
}
END{if n==0}
}' tmpsrc srcfile.txt

Thanks in advance

You cannot expect us to discover a broken program's intended purpose. We can't see what it's supposed to be doing if you don't explain.

What is it supposed to be doing?

In what way does it 'not work'?

What data are you using it with?

1 Like

Thanks for your reply.

I am going to update the explaination.

Two syntax errors. Within { } the syntax is different

awk -F',' 'BEGIN {n=0}
{
if (NR == FNR) {fname[$1]; next}
if ($3==fname) n=1
}
END {if (n==0) print}
'

Parts of the main (or the whole main block) can be without { } then the syntax for an implicit if is

awk -F',' 'BEGIN {n=0}
NR == FNR {fname[$1]; next}
{
if ($3==fname) n=1
}
END {if (n==0) print}
'

Since some time I add brackets to the implicit if, to emphasize the similarity with an explicit if:

(NR == FNR) {fname[$1]; next}

The implicit if can have an implicit action that is {print}. The explicit if must have an explicit action.

1 Like

Thanks for your such detail explanation, you are great.

More question, what i want to do is:

I have one file called filelist, this is static file. this file is master file for checking source send file status. file like below:
group, filename
abc,file1
abc,file2
abc,file3
cde,file4
cde,file4
def,file5
everyday, I need to check if the all file come or not group by group. which means for group abc, if I found file1, file2, file3,file4 then send group message to downstream (group file completed). if any file missing, I need to send warning. there are about 50 group 150 files. I am DB developer, not that strong in unix. I cannot figure out how to loop file based on group count, so, my idea is:
use awk find the file not existing in dir, then, uniq the group for both file list and the above scritp return, then do some sort of minus using filelist - result return from script, this I can get the file completed group list.
Do you have any suggestion about how to work for this.

Thanks

:b: