awk Can't open file

Hello all,

I am creating a small bash script to cycle through some files that are the results of an analysis I have run (I am a statistician). There are many folders called job001, job002,...,job135. Each folder has a text file called results.txt. I want to create two summary files of the results - one which holds a list of ALL of the values in column 3 of every file, and one which checks the value in column 3 ( for all rows of all results files) and outputs the entire row if it is below a critical value. My code (for the first 2 folders - will change njobs to 135 when it works!):

njobs=2
crit=0.0000005
path="/Users/jm/"

for (( i=1;i<=$njobs;i++)); do
	jobnumber=$(printf "%03s" $i)  
	currentfile="${path}""job${jobnumber}"/results.txt
	echo $currentfile
	awk '$3<crit {print $0}' currentfile >> mhc_significant_results
	awk '{print $3}' currentfile >> lrt_pvals
	done

The echo $ currentfile prints out the correct filename & path. Results:

/Users/jm/job001/results.txt
awk: can't open file currentfile
source line number 1
awk: can't open file currentfile
source line number 1
/Users/jm/job002/results.txt
awk: can't open file currentfile
source line number 1
awk: can't open file currentfile
source line number 1

Can anyone suggest why the awk script can't seem to find and/or open the file? I suppose it's probably some misplaced or missing quotes or $ somewhere, but I can't spot it!

Many thanks in advance,
Jen

	awk '$3<crit {print $0}' $currentfile >> mhc_significant_results
	awk '{print $3}' $currentfile >> lrt_pvals

I think you are missing $ before the variable name.

 
 awk '$3<crit {print $0}' $currentfile >> mhc_significant_results
awk '{print $3}' $currentfile >> lrt_pvals

Thanks, that's it! Silly me.