I don't know how to do this with awk But my target is to create awk one line syntax in order to print the second field ($2) if all first field ($1) are true
for example
I have the file:
true my_name_is_lenon
true my_name_is_lenon
true my_name_is_lenon
false my_name_is_lenon
true my_name_is_lenon
false my_dog_is_fat
true my_dog_is_fat
true my_dog_is_fat
true I_am_very_tall
true I_am_very_tall
true I_am_very_tall
true my_ball_is_fine
true my_ball_is_fine
the awk will print only the following:
I_am_very_tall
my_ball_is_fine
Because I_am_very_tall , my_ball_is_fine get true on the first field without false
my_dog_is_fat , my_name_is_lenon not printed because the false word on the first field
The rule is to print the second field if no false word on the first field! (Of all the same sentence on the second field)
lidia
Here is one way:
awk '{if ($1 == "false") {array[$2] = $1} else if (array[$2] != "false") array[$2] = $1} END {for (i in array) if (array[i] == "true") print i}' inputfile
Edit:
Here it is on multiple lines:
awk '{if ($1 == "false")
{array[$2] = $1}
else if (array[$2] != "false")
array[$2] = $1}
END {for (i in array)
if (array[i] == "true")
print i}
' inputfile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With