[gridengine users] reading arguments using awk with escaped variables

Sara Rolfe smrolfe at u.washington.edu
Tue Apr 17 03:46:38 UTC 2012


Hello,
I have a list of jobs with arbitrary inputs which I would like to  
submit.  I wanted to try and get around the sequential argument  
requirement by reading the input arguments from a text file using:
$infile=$(awk "NR==$SGE_TASK_ID" /myPath/fileList.txt)
However, when I try echo "$infile" it is blank.  I realized that I  
needed to escape the variables in my script, and this is causing me  
problems.  I can get the correct output from awk using:
awk "NR==\$SGE_TASK_ID" /myPath/fileList.txt
And I can correctly assign $infile if I hard code the line number like:
infile=$(awk "NR==1" /myPath/fileList.txt)
So I think I have boiled down the problem to getting the command  
substitution to handle the escape, since just adding the escape to the  
first version does not work. I also attempted to use awk's variable  
passing:
infile=$(awk -v "line=/$SGE_TASK_ID" 'NR == line' /myPath/fileList.txt)
But this produced the same blank output to echo \$infile (I needed to  
escape this variable too).  I would appreciate any advice on how to  
get the escaped variables to be handled properly or on why my  
variables need to be escaped.  Examples that I've seen from other  
users on my compute cluster use escaped variables, but I've noticed  
that many other examples on line do not.  I'd like to understand why I  
need to use them and if there's any way around it.
Thanks,
Sara




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gridengine.org/pipermail/users/attachments/20120416/bf2b9446/attachment.html>


More information about the users mailing list