Firstly, please use [code][/code] tags when showing code or data.
Ok ... I think I get you.
The short answer is no you can't at least not the way you have tried (obviously).
Code:
var="$1=="DANNY" && $NF=="N"";
This will create a string which will still be a string when used in awk, hence your if in the script would be the same as saying:
Code:
if("==DANNY && ==N")
This will always evaluate to true.
If you are wondering why your string is incomplete:
$1 will only have a value if an argument has been passed to the script
$NF is only known to awk unless you create a variable in bash with the same name
Hence both your strings are blank.
The $ symbol in bash is used to return the value assigned to a variable whereas in awk it is used to return the indirect value (ie if NF = 6 then $NF returns the item in the sixth column)
This is why $var has not worked and thrown an error in awk
Your assigment for the awk variable is the wrong way around:
Here $var is not a legal name and even if it were, you would be assigning nothing as to call the value of a bash variable you need to use $.
So correct line would be:
This will get us to the situation I explained earlier though for when we now do:
This will test that the variable has a value which is true (always unless $var from bash is empty)
The only way I can think of off the top of my head would be to assign all the values for the tests into a single string and then split into an array and test.
If you then wanted to perform other tests, ie not just equals to, this would be come very complicated as you would need to test for the test and perform each as found??
So this method would be:
Code:
var="1 DANNY NF N"
awk -v var="$var" 'BEGIN{n = split(var, arr);}{<perform tests on each part of array arr testing 1 against 2, 3 against 4 ...>}'
Not sure if that helps. generally I would say you need to rethink your process and what your goal is as perhaps this is not the best method