if: expression syntax error in gawk

I'm pretty new to shell scripting, but I am catching on quick. I did see one of the stickied threads about the csh, and I think this is relevant, but I don't understand enough to make a decision based on it. So as you'll see below, I use the |csh pipe, and if that is not correct, I'm certainly open to learning how to change it.

I maintain a list of jobs that I've submitted to the server (this is just a file I create and update). I can pull up a list of jobs that are in the queue or running. My goal is to grab the list of running/queued jobs, and compare that to the my list, and output the jobs that are no longer in the queue (meaning they've completed).

My crude attempt is as follows:

gawk '/jobID:/ {print "qstat -u jmarell | if [ `grep -c " $2 "` -eq 0 ]; echo " $2 }' ~/curJobs.log | csh

So grab the lines from my static file (curJobs.log), and pull the 2nd field which contains the jobID. Then pull up the list of running jobs, and see if that jobID is found with grep. If it is not found, then echo that job ID.

The output then is (2nd line is a jobID, but not the correct one):

if: Expression Syntax.
348240

This is in fact just the very first job in the list, it is not the correct result.

I have tried so many different iterations of the if statement trying to find the correct format, and I have not succeeded. I've read through the gawk if statement tutorial where they use if ( x % 2 == 0), and such, I've tried to format in similar ways. With and without ` or ", and I am sure I'm missing some fundamental understanding of how I'm to combine these pieces.

Any guidance in solving this problem would be greatly appreciated :slight_smile:

The syntax of the generated if statement is not valid in csh.

qstat -u jmarell | if [ `grep -c 348240` -eq 0 ]; echo 348240

A solution is to generate a statement like that :

qstat -u jmarell | grep -q 348240 || echo 348240

Another approch to solve your problem :

qstat -u jmarell |
awk '
    FILENAME=="-" { JobId[$1] = $2; next }
    ! ($2 in JobId) { print "Job id", $2, "not found" }
' - ~/curJobs.log

jean-Pierre.

Oh, perfect thank you! I think I understand both of those pretty good.