AWK multiple conditionals not printing
-
12-06-2021 - |
Question
I'm looking for zoom to understand why this:
palabra=s_gonzalez
i=10
awk -vvar1=$palabra -vvvar2=$i '( $1 == var1 ) && ( $2 == var2 ) {print $0}' As
is not printing anything. The As
file contains:
r_castillo 10
flores 6
s_gonzalez 10
o_gutzwiller 12
h_ji 4
Thanks in advance for any suggestion.
La solution
Where're your:
vvar2
Did you misspell var2
?
Autres conseils
As a technique to avoid this sort of problem, you can assign variables without -v
. I would rewrite the command:
awk '$1==var1 && $2==var2' var1=$palabra var2=$i As
It always seems simpler to me to assign variables as arguments after the program rather than as -v
options before the program. (-v
assignments are available in the BEGIN
block, but that is irrelevant in this case.)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow