Hi! I'm reasonably new to awk and shell scripting, and am having difficulties with getting my shell script to set an environment variable based on the awk output from within a shell. I need to be able to reset the variable for each pass of a loop.
Basically, I fetch the name from a file using
awk 'NR==2' R0-results.mol2
And I need to be able to use this output to set the variable mol2file within my shell script run within csh.
I have tried:
awk 'NR==2 {print "set mol2file=" $0}' R0-results.mol2 | sh
and
awk 'NR==2 {print "set mol2file=" $0}' R0-results.mol2
as well as a few other variations that were erased, but all commands will generate the correct command when run at the command line:
set mol2file=pp_5_188_000
which then sets the variable when run as echoed as above. However, I cannot get it to invoke the set variabel command from within the shell script.
I also tried used a system call function:
awk 'NR==2 {system("set filsname=" $0)}' R0-results.mol2
But again, it has the correct command when echoed, but will not be invoked from within the shell script.
What am I doing wrong? How do I invoke a set variable command from within a shell script based on my awk output?
Any help is greatly appreciated!
Thanks!
Basically, I fetch the name from a file using
awk 'NR==2' R0-results.mol2
And I need to be able to use this output to set the variable mol2file within my shell script run within csh.
I have tried:
awk 'NR==2 {print "set mol2file=" $0}' R0-results.mol2 | sh
and
awk 'NR==2 {print "set mol2file=" $0}' R0-results.mol2
as well as a few other variations that were erased, but all commands will generate the correct command when run at the command line:
set mol2file=pp_5_188_000
which then sets the variable when run as echoed as above. However, I cannot get it to invoke the set variabel command from within the shell script.
I also tried used a system call function:
awk 'NR==2 {system("set filsname=" $0)}' R0-results.mol2
But again, it has the correct command when echoed, but will not be invoked from within the shell script.
What am I doing wrong? How do I invoke a set variable command from within a shell script based on my awk output?
Any help is greatly appreciated!
Thanks!