I'm trying to write a bash script which will submit as numerous simultaneous jobs. At one point in the script I want it to find a value from a specific cell in a table based on the job ID number.
The issue is that I am trying to use awk
to return the value based on an using a sum in the awk command, which I cannot get to work.
The issue is that I cannot just use the Job ID as a variable because that will print the value one row up from the row I actually want (because awk row 1
will be the header). So I actually need row = Job_ID + 1
I think one potential solution is that I could store it in a variable like so:
counter=$((${SGE_TASK_ID}+1))
And then pass it as follows:
gene=awk -v counter=$counter 'FNR == $counter {print $2; exit}' "$mainDir"inputs/genelist.tsv
However, I am not certain whether this will work (as I am fairly inexperienced with awk) and also would like to ask for posterity whether there is a method of performing the addition within the awk command.
Something like:
gene=awk 'FNR == "$((${SGE_TASK_ID}+1))" {print $2; exit}' "$mainDir"inputs/genelist.tsv
The end result should be the value of the cell in row n+1 from column 2 in the file genelist.tsv
Thus far when using the addition method within awk it has simply been returning nothing, or an error saying that the command cannot be found.
Edit: It's maybe worth mentioning that in this case the variable of mainDir
is defined earlier like so:
mainDir="/exports/lab/projects/prj_099/"