The following is part of a larger shell script
grep -v "Col1" my_test.log | grep -v "-" | awk '$5 == "Y" {print $1}'
instead of printing, can I set set $1 to a variable that the rest of the shell script can read?
if $5 == Y, I want to call another shell script and pass $1 as a variable.
joeyg
September 6, 2011, 4:17pm
2
Such that...
I assign variable parm to the result of a calculation
Show that it is set
Then print out that "6th" column in an awk statement
*Note that I set col (within awk) to be equal to variable parm
$ parm=$(ls sample*.txt | wc -l)
$ echo $parm
6
$ head sample3.txt | awk -v col=$parm '{print $col}'
46.6432798439
48.8478948517
45.8022601455
48.780669145
47.7312017846
41.7389244255
54.1498530714
X
41.709838673
41.4599808018
Are you trying to do something like this?
Without seeing your file(s), it is hard to understand what you are trying to do.
kato
September 6, 2011, 6:13pm
3
If you use awk instead of grep then you can set $1 into a local variable:
new_var=$(awk '!/Col1/ && !/-/ && $5=="Y"{print $1}' my_test.log)