0

I did find answers to this question, what I don't understand is why what seems to work for other is not working for me. I have a text file with a list of sample names. I want to extract these samples names individually and assign it to a variable, in order to run an array job.

The file is a samples.txt:

sample_id_a
sample_id_b
sample_id_c

Using the command:

qsub -t 1-3 test_job.sh

My script is the following: Using the task id index, I want to retrieve the sample id of line x and assign it to VAR, then print it.

#!/bin/bash

echo "The increment is ${SGE_TASK_ID}"

VAR=$(awk 'NR==${SGE_TASK_ID}' samples.txt)

echo " The sample is ${VAR}"

The output is:(here example for output number 1)

The increment is 1
The sample is

So SGE_TASK_ID is correct, but I fail to retrieve and echo the corresponding string in my .txt file.

Thank you, Camille

samthegolden
  • 1,366
  • 1
  • 10
  • 26
CAsimonet
  • 21
  • 2
  • Update: In the terminal, if I do `awk 'NR==1' samples.txt`, it works. But if I do `VAR=1` and then `NR==$VAR' samples.txt`, it does not. I do not get an error but the output is nothing. – CAsimonet Nov 08 '17 at 10:55
  • 1
    Many thanks!!! I did not though of the quotes. You can delete his post I guess. – CAsimonet Nov 08 '17 at 11:05

0 Answers0